Why this PHP line not printing the the Error message? -
in 1 of file wrote these statements. instead of printing error message generates page normal errors.
try { $var = 90 / 0; // error dvide 0 } catch (exception $e) { die( 'something gone wrong'); }
a php error not same php exception. in script, no exceptions thrown - error occurs.
you same result if install custom error handler:
<?php // install temporary error handler set_error_handler(function($error) { die("something wrong"); }); // invalid $var = 90 / 0; // error dvide 0 // restore previous error handler restore_error_handler(); ?>
if you're real fan of exceptions, install error handler automatically turns errors php exceptions:
<?php // install error handler turns error exceptions set_error_handler(function($error) { throw new exception($error); }); // open try-catch block catch exceptions try { // invalid $var = 90 / 0; // error dvide 0 } catch (exception $exception) { // oops die("something wrong"); } ?>
Comments
Post a Comment