Wednesday, 15 June 2011

Exception handling in this PHP? -



Exception handling in this PHP? -

how can handle exception in php? example, in code this:

<?php $a=5; $b=0 $c=($a/$b); echo $c; ?>

please help me.

php raises warnings , error messages not throwing exception, hence cannot grab here. however, can modify behaviour:

// register custom error handler throws errorexception // whenever warrning or error occurs set_error_handler(function ($errno, $errstr, $errfile, $errline ) { throw new errorexception($errstr, 0, $errno, $errfile, $errline); }); $a = 5; $b = 0; // partition 0 result errorexception beingness thrown seek { $c = $a / $b; echo $c; } grab (errorexception $e) { echo 'error: ' . $e->getmessage(); }

php exception exception-handling

No comments:

Post a Comment