mottwsc Posted August 1, 2009 Share Posted August 1, 2009 Anytime an error/exception occurs in my php 5 code, I'd like to have the specific error written to a table along with other info (user, date, etc.) and have a more user-friendly message sent to the user. These user-friendly messages could be fairly generic (maybe 10 or 20 different ones in total) or they could be more specific if that doesn't require a lot more coding. I'm somewhat familiar with the catch/try methodology, but it seems like I would have to put in a lot of extra code all through each program to achieve this. Is there a way to have exceptions/errors handled without all of those specific try/catch blocks? Thanks. Link to comment https://forums.phpfreaks.com/topic/168408-error-handling-without-specific-trycatch-blocks/ Share on other sites More sharing options...
ignace Posted August 1, 2009 Share Posted August 1, 2009 There are a few ways: 1. Create a fallback try/catch. try { //application code } catch (Exception $e) { //catches any uncaught exception's } 2. Use set_error_handler() & set_exception_handler() set_error_handler('error_handler'); set_exception_handler('exception_handler'); function error_handler($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array()) {} function exception_handler($exception) {} Link to comment https://forums.phpfreaks.com/topic/168408-error-handling-without-specific-trycatch-blocks/#findComment-888366 Share on other sites More sharing options...
mottwsc Posted August 1, 2009 Author Share Posted August 1, 2009 OK - thanks. I will look into these further. Link to comment https://forums.phpfreaks.com/topic/168408-error-handling-without-specific-trycatch-blocks/#findComment-888369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.