-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ErrorsToExceptions to enobrev/tools
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* http://us3.php.net/manual/en/function.set-error-handler.php#112881 | ||
* throw exceptions based on E_* error types | ||
*/ | ||
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context) | ||
{ | ||
// error was suppressed with the @-operator | ||
if (0 === error_reporting()) { return false;} | ||
switch($err_severity) | ||
{ | ||
case E_ERROR: throw new ErrorException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_WARNING: throw new WarningException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_PARSE: throw new ParseException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_NOTICE: throw new NoticeException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_CORE_ERROR: throw new CoreErrorException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_CORE_WARNING: throw new CoreWarningException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_COMPILE_ERROR: throw new CompileErrorException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_COMPILE_WARNING: throw new CoreWarningException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_USER_ERROR: throw new UserErrorException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_USER_WARNING: throw new UserWarningException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_USER_NOTICE: throw new UserNoticeException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_STRICT: throw new StrictException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_RECOVERABLE_ERROR: throw new RecoverableErrorException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_DEPRECATED: throw new DeprecatedException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
case E_USER_DEPRECATED: throw new UserDeprecatedException ($err_msg, 0, $err_severity, $err_file, $err_line); | ||
} | ||
}); | ||
|
||
class WarningException extends ErrorException {} | ||
class ParseException extends ErrorException {} | ||
class NoticeException extends ErrorException {} | ||
class CoreErrorException extends ErrorException {} | ||
class CoreWarningException extends ErrorException {} | ||
class CompileErrorException extends ErrorException {} | ||
class CompileWarningException extends ErrorException {} | ||
class UserErrorException extends ErrorException {} | ||
class UserWarningException extends ErrorException {} | ||
class UserNoticeException extends ErrorException {} | ||
class StrictException extends ErrorException {} | ||
class RecoverableErrorException extends ErrorException {} | ||
class DeprecatedException extends ErrorException {} | ||
class UserDeprecatedException extends ErrorException {} |