Re: How can I detect an exception without using try/catch?

From: Date: Fri, 24 Apr 2009 11:40:21 +0000
Subject: Re: How can I detect an exception without using try/catch?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-291920@lists.php.net to get a copy of this message
Ok, the details of the problem obviously aren't being understood. Let's assume that I explained it poorly and I'll try again. Take the following code (It's complete, cut/paste to see what happens.): <?php class running { private $running; public function __construct() { $this->running = true; } public function stop() { $this->running = false; } public function __destruct() { if ($this->running) { throw new exception('I have not stopped running yet!'); } } } function fail_horribly() { throw new exception('This is the real error that I want a stack trace from'); } function do_that_thing() { $running = new running(); fail_horribly(); $running->stop(); } try { do_that_thing(); } catch (exception $e) { echo $e->getMessage(); } ?> While putting this together, I discovered lots of interesting behaviour. Depending on exactly where I put the try/catch, there are different things that happen and different errors that occur. It's kinda interesting. The thing is, that none of those errors is the result that I _want_ which is to ignore the fact that $running was unset and just report the error that started everything going wrong. If I could put my fictional function (get_current_exception()) in the __destruct() method, I could detect that an exception was already in progress and avoid throwing another one. -- Bill Moran http://www.potentialtech.com http://people.collaborativefusion.com/~wmoran/

« previous php.general (#291920) next »