175
ProFessIonAl exCePtIon And error HAndlIng
To configure error conversion to ErrorExceptions, implement set_error_
handler() like this.
fu nction convertToException($errNo, $errStr, $errFile, $errLine,
$errContext)
{
if (error_reporting() = = 0) return;
thr ow new ErrorException($errStr, 0, $errNo, $errFile,
$errLine);
}
set_error_handler('convertToException');
Now, PHP errors are converted to exceptions and rethrown as ErrorException
objects, allowing them to be caught by catch handlers. is facilitates designing a
consistent error handling structure for an application.
Note that the function signature for the handler must be exactly as specified.
Following is an excerpt from the online PHP Manual:
Error Handler Function Specification
A callback w ...