12
Errors handling Webinar PHParty7 France - 28/11/15

Webinar PHParty7 - Errors handlings

Embed Size (px)

Citation preview

Page 1: Webinar PHParty7 - Errors handlings

Errors handlingWebinar PHParty7 France - 28/11/15

Page 2: Webinar PHParty7 - Errors handlings

Errors VS Exceptions

Page 3: Webinar PHParty7 - Errors handlings

Errors VS Exceptions

E_ERROR, E_WARNING, E_PARSE, E_NOTICE, ...

Errors

Page 4: Webinar PHParty7 - Errors handlings

Errors VS Exceptions

Exception, RuntimeException, ErrorException, ...

Exceptions

Page 5: Webinar PHParty7 - Errors handlings

Actual Exception hierarchy

Page 6: Webinar PHParty7 - Errors handlings

Actual Exception hierarchy

Page 7: Webinar PHParty7 - Errors handlings

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();}

Page 8: Webinar PHParty7 - Errors handlings

Fatal Errors

● Fatal errors cannot be gracefully handled● Error handler is not called● Finally block will not be invoked● Destructors are not called

Page 9: Webinar PHParty7 - Errors handlings

PHP7 Exceptions

Page 10: Webinar PHParty7 - Errors handlings

PHP7 Exceptions

Page 11: Webinar PHParty7 - Errors handlings

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()

Page 12: Webinar PHParty7 - Errors handlings

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/…