0

Consider this sample code:

<?    
try {
        throw new Exception('new');
    } catch (Exception $ex) {
        echo "caught";
    }
?>

I assume this should just output the string "caught" when run. However, with display errors turned on, I see the exception shown on the web page like ( ! ) Exception: new in test.php on line 2 along with a dump of call stack and variables in scope.

With display errors off, it doesn't show the exception notice. Shouldn't the try catch block prevent the notice to be shown even with display errors on?

5
  • 1
    What you quote doesn't look like the ordinary PHP error reporting. Do you have a custom error handler registered in your script? Commented Oct 19, 2012 at 17:53
  • No.. I just have ini_set('display_errors',1); at the beginning of the script. Commented Oct 19, 2012 at 18:03
  • And that ( ! ) is in the error message? Literally? Strange. Commented Oct 19, 2012 at 18:05
  • Ya, it shows (!) before the exception notice. Aren't you able to replicate this with ini_set('display_errors',1); ? Commented Oct 19, 2012 at 18:14
  • which version of PHP do you have? The code you provided runs fine on my system. Commented Oct 19, 2012 at 21:42

1 Answer 1

1

If you are using xdebug and you do not want to disable xdebug or error reporting and you do not want trace messages of caught exceptions to appear, you can turn off the display of the exception trace with

xdebug.show_exception_trace = 0

in your php.ini

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.