Re: newbie: deactivate query before freeing?
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 11:02:54 +0200
"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
.
- References:
- newbie: deactivate query before freeing?
- From: swansnow
- Re: newbie: deactivate query before freeing?
- From: Maarten Wiltink
- Re: newbie: deactivate query before freeing?
- From: swansnow
- newbie: deactivate query before freeing?
- Prev by Date: Re: newbie: deactivate query before freeing?
- Next by Date: Re: newbie: deactivate query before freeing?
- Previous by thread: Re: newbie: deactivate query before freeing?
- Next by thread: Re: newbie: deactivate query before freeing?
- Index(es):
Relevant Pages
|
|