chainedExceptionHandler; } /** * Get a list of Exception and other Throwable classes that will be logged * @return array */ public function getLoggedExceptionClasses() { return $this->logExceptionClasses; } /** * Log these types of errors or exceptions * * @param string $class Exception class name */ protected function logUncaughtException($class) { if (!in_array($class, $this->logExceptionClasses)) { $this->logExceptionClasses[] = $class; } $this->initExceptionHandler(); } /** * Use the global error handler */ protected function initExceptionHandler() { if (!isset($this->chainedExceptionHandler)) { $this->chainedExceptionHandler = $this->setExceptionHandler([$this, 'handleException']) ?: false; } } /** * Uncaught exception handler * @ignore * * @param \Exception|\Error $exception */ public function handleException($exception) { $this->setExceptionHandler(null); $this->setErrorHandler(null); $isInstanceOf = array_map(function ($class) use ($exception) { return is_a($exception, $class); }, $this->logExceptionClasses); if ($exception instanceof \Error || $exception instanceof \ErrorException) { $type = $exception instanceof \Error ? $exception->getCode() : $exception->getSeverity(); $shouldLog = $this->getLoggedErrorTypes() & $type; } else { $shouldLog = array_sum($isInstanceOf) > 0; } if ($shouldLog) { $this->log($exception); } $this->callOnFatalError($exception); if ($this->chainedExceptionHandler) { call_user_func($this->chainedExceptionHandler, $exception); } throw $exception; // This is now handled by the default exception and error handler } }