unknown exception error in php

Posted by fayer on Stack Overflow See other posts from Stack Overflow or by fayer
Published on 2010-05-09T06:50:31Z Indexed on 2010/05/09 6:58 UTC
Read the original article Hit count: 236

Filed under:

i wanna catch all exceptions thrown in a script and then check if they have a error code 23000.

if they don't i want to rethrow the exception.

here is my code:

function myException($exception) {
    /*** If it is a Doctrine Connection Mysql Duplication Exception ***/
    if(get_class($exception) === 'Doctrine_Connection_Mysql_Exception' && $exception->getCode() === 23000) {
         echo "Duplicate entry";
    } else {
         throw $exception;
    }
}

set_exception_handler('myException');

$contact = new Contact();
$contact->email = 'peter';
$contact->save();

but i get this error message and i dont know what it means:

Fatal error: Exception thrown without a stack frame in Unknown on line 0

i want to be able to rethrow the original error message if it has not the error code 23000.

even when i deleted the check errorcode i still get the same message:

function myException($exception) {
    throw $exception;
}

set_exception_handler('myException');

$contact = new Contact();
$contact->email = 'peter';
$contact->save();

how could i solve this?

thanks

© Stack Overflow or respective owner

Related posts about php