Upload
darkmira
View
154
Download
2
Embed Size (px)
Citation preview
Errors handlingWebinar PHParty7 France - 28/11/15
Errors VS Exceptions
Errors VS Exceptions
E_ERROR, E_WARNING, E_PARSE, E_NOTICE, ...
Errors
Errors VS Exceptions
Exception, RuntimeException, ErrorException, ...
Exceptions
Actual Exception hierarchy
Actual Exception hierarchy
Error & Exception handling
Error handling
Exception handling
set_error_handler(function ($errno, $errstr, $errfile, $errline) { echo "Error $errstr at line $errline";});
try { mayThrowException();} catch (Exception $e) { echo 'Exception: '.$e->getMessage();}
Fatal Errors
● Fatal errors cannot be gracefully handled● Error handler is not called● Finally block will not be invoked● Destructors are not called
PHP7 Exceptions
PHP7 Exceptions
Error & Exception handlingErrors and fatal errors handling
try { inexistant_function();} catch (Error $e) { echo 'Error: '.$e->getMessage();}
// PHP5:// Fatal error: Call to undefined function// inexistant_function() in …// PHP7:// Error: Call to undefined function inexistant_function()
Bibliography
RFC for EngineException: https://wiki.php.net/rfc/engine_exceptions_for_php7
Reviewed RFC about Throwable: https://wiki.php.net/rfc/throwable-interface
Article about PHP7 Throwable and Errors: https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/
Stackoverflow, Errors VS Exception:http://stackoverflow.com/questions/…