I also would like someone to tell me why exceptions cannot be
called in the
destructor? Since they can't, this means the reliability of a
destructor is
uncontrolled and nothing can be done to see if this completes
successfully.
Your question is kindof wrong... you can always throw exceptions in
destructors. The problem is CATCHING them.
I think probably in languages with GC's that throwing [uncaught]
exceptions in destructors is probably a bad idea, unless you DESIRE
termination as a result, as you don't know who's calling your
destructor. I am not positive that this is a bad idea, but I think
so... exceptions are meant to be caught. Uncaught exceptions are
typically considered errors, and PHP considers them fatal.
This is precisely what's happening to you. The destructor is called
from the script termination cleanup code, outside of your program
scope, and thus there's no try/catch to catch your exception. I
suppose if you really want to do this just for logging, you could use:
http://us2.php.net/manual/en/function.set-exception-handler.php
But to me this seems like a bad idea.
If you have some complicated tear-down machinery that you want to do
try/catch with, try a method like "cleanup()" in your class and call
it surrounded by try/catch to do your cleanup when you're done with
the resource.
Alan
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php