Re: newbie: deactivate query before freeing?



"swansnow" <schultz@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1127950675.863873.233630@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
> See if I'm right:
>
> This way, if the Create failed, then myQuery is an invalid reference,
> and trying to use it will result in an exception, in which case, it
> will be assigned nil, but the exception will still be thrown.

No, that's not what happens.

Let's distinguish first between an "invalid" and a "useless" reference.
There is exactly one invalid reference, the null pointer, nil. That's
a useful thing for a function to return in case of problems, but the
code that calls the function then needs to check the return value
before using it. Every time. This can be a bit of a chore.

Incidentally, constructors are magic and can't return nil without outside
help or major hackery.

Any dangling pointer is a useless reference. A function should never
return a dangling pointer in any case, but certainly not without making
it clear through other means (another Boolean parameter for example) that
the value isn't valid.

More commonly, a failing constructor will raise an exception. This will
abort the normal flow of execution and start handling the exception
instead. The nearest enclosing try statement (whether try-except or
try-finally) will be located and its handler clause entered. If it is
necessary for this to abort and leave any procedures, this is done. No
code in the procedure will be executed, there will be *no return value*
from functions, and your assignment above (snipped) doesn't happen. Nor
does the code after it; it needs to be an _enclosing_ try statement.

Exception handling only stops in an except clause that handles the
exception (and does not reraise it), or when the exception leaves your
program altogether. The latter ends your program.


> If the Create succeeded then the query will execute and so forth. If
> an exception occurs in the "try" code, the reference will be freed,
> and then the exception will be thrown. If no exceptions are generated,
> the reference still gets freed, and everything's fine.

Yes.

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Dataset retunring Null ..a gurus opinion required!
    ... How is estateOleAdapter initialized? ... toolbox to the design area to establish the connection. ... application this exception comes up): ... When adding a reference, I tried "Add Service Reference" and I also ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: "invalid handle", sockets, threads and garbage collector
    ... your IntPtr value happens to coincide with a reference. ... The exception contains "invalid handle" message. ... Socket constructor problem ... finalization means closing the handle to resource. ...
    (microsoft.public.dotnet.framework.clr)
  • Global Assembly Cache Issue
    ... I have a dll that I use in several projects, that I placed in the Global ... you can see in the Exception below). ... If I change the Copy Local property of the reference to True, ... Attempting download of new URL ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: PowerPoint shapeId/ShapeName property changes/Increments autom
    ... I agree with what u r saying, reference is stored in a shape type variable ... which result in a com exception in my code. ... >> I am posting a small sample code to better explain my problem ... >> Sub Testing() ...
    (microsoft.public.office.developer.vba)
  • Re: Updating a DB via SQL is giving me a headache
    ... problem will never be executed using the Try/Catch block, ... Connection was certainly created and opened, ... If so, null is not an Integer, and that could throw an exception. ... is handled, execution continues. ...
    (microsoft.public.dotnet.framework.aspnet)