David
David

Reputation: 1312

I can't catch php exceptions using try....catch

I'm having a problem with PHP Exceptions. Even if I try to execute this code:

try {
    $some->knownMethodWithError();
} catch(Zend_Exception $exp){
    echo 'Error!: ' . $exp->getMessage();
}

My apache/php served web page always display a 500 Error. I mean,

echo 'Error!: ' . $exp->getMessage();

never is executed. I've tested with a redirection instead of that echo, but it doesn't work. Is there some php.ini directive that cause this behavior, or could it be something else?.

This happens in my Zend Framework based project.

Upvotes: 2

Views: 4415

Answers (2)

Frederic Bazin
Frederic Bazin

Reputation: 1529

Also, your code will only catch Zend_Exception. If you have custom Exceptions maybe catch(Exception $e) will get more chances to catch all of them

maybe you could run the script with full logs. Change your php.ini on the server on the line :

error_reporting=E_ALL | E_STRICT

or better run it on an IDE environment with a debugger.

Upvotes: 5

Chris Eberle
Chris Eberle

Reputation: 48775

A 500 error isn't a PHP exception, it's happening above the code level. A 500 error means that there was an error while PHP was trying to parse your script (probably). Possibly your code has a syntax error.

Upvotes: 3

Related Questions