123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace Hoa\Exception;
- class Error extends Exception
- {
-
- public function __construct(
- $message,
- $code,
- $file,
- $line,
- array $trace = []
- ) {
- $this->file = $file;
- $this->line = $line;
- $this->_trace = $trace;
- parent::__construct($message, $code);
- return;
- }
-
- public static function enableErrorHandler($enable = true)
- {
- if (false === $enable) {
- return restore_error_handler();
- }
- return set_error_handler(
- function ($no, $str, $file = null, $line = null, $ctx = null) {
- if (0 === ($no & error_reporting())) {
- return;
- }
- $trace = debug_backtrace();
- array_shift($trace);
- array_shift($trace);
- throw new Error($str, $no, $file, $line, $trace);
- }
- );
- }
- }
|