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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



uhm, I did not read it, you are right ... well, take this code as a joke, OK?

<?php
function exception_handler($exception) {
    echo "Error: " , $exception->getMessage(), "\n";
    if($checkSomethingAndEventuallyContinue = true){
        $line = $exception->getLine();
        $php = explode(PHP_EOL, file_get_contents($exception->getFile()));
        while($line--)
            array_shift($php);
        eval(implode(PHP_EOL, $php));
    }
}

set_exception_handler('exception_handler');
throw new Exception('Uncaught Exception');
echo "Not Executed\n";
?>


> Date: Fri, 24 Apr 2009 07:07:10 -0400
> From: wmoran@xxxxxxxxxxxxxxxxx
> To: an_red@xxxxxxxxxxx
> CC: php-general@xxxxxxxxxxxxx
> Subject: Re:  How can I detect an exception without using try/catch?
> 
> In response to Andrea Giammarchi <an_red@xxxxxxxxxxx>:
> > 
> > http://uk2.php.net/set_exception_handler
> > http://uk2.php.net/manual/en/function.set-error-handler.php
> 
> Thanks for the reply, Andrea.  However, you either didn't read my
> entire message, or didn't understand it.  I can't use either of
> those to detect an exception that's already in progress, I can only
> use them to catch the exception before the script ends if nothing
> else catches it.
> 
> What would be nice is a function like get_current_exception() that
> would either return the current exception object, or return false
> if there is no exception.
> 
> > > Date: Thu, 23 Apr 2009 12:19:30 -0400
> > > From: wmoran@xxxxxxxxxxxxxxxxx
> > > To: php-general@xxxxxxxxxxxxx
> > > Subject:  How can I detect an exception without using try/catch?
> > > 
> > > 
> > > Specifically, the __destruct() method of certain objects will be
> > > called if an object goes out of scope due to an exception.  Since
> > > the __destruct() method didn't call the code that caused the
> > > exception, it can't catch it.
> > > 
> > > I need the __destruct() method to behave differently if it's
> > > called while an exception is in progress than if it's called
> > > simply because the object is unset.
> > > 
> > > Searches of the docs has yet to turn up anything and Google isn't
> > > helping.  Anyone have any pointers?
> > > 
> > > -- 
> > > Bill Moran
> > > http://www.potentialtech.com
> > > http://people.collaborativefusion.com/~wmoran/
> > > 
> > > -- 
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > 
> > 
> > _________________________________________________________________
> > Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
> > 
> > http://www.microsoft.com/windows/windowslive/products/photos.aspx
> 
> 
> -- 
> Bill Moran
> http://www.potentialtech.com
> http://people.collaborativefusion.com/~wmoran/

_________________________________________________________________
Show them the way! Add maps and directions to your party invites. 
http://www.microsoft.com/windows/windowslive/products/events.aspx

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux