protected function error($err)
    {
        $type = get_class($err);
        $msg = $err->getMessage();

        try {
            if (!$this->error_callbacks->isEmpty()) {
                foreach ($this->error_callbacks as $callback) {
                    if (is_callable($callback)) {
                        if (is_string($callback)) {
                            $callback($this, $msg, $type, $err);

                            return;
                        } else {
                            call_user_func($callback, $this, $msg, $type, $err);

                            return;
                        }
                    } else {
                        if (null !== $this->service && null !== $this->response) {
                            $this->service->flash($err);
                            $this->response->redirect($callback);
                        }
                    }
                }
            } else {
                $this->response->code(500);

                while (ob_get_level() >= $this->output_buffer_level) {
                    ob_end_clean();
                }

                throw new UnhandledException($msg, $err->getCode(), $err);
            }
        } catch (Throwable $e) { // PHP 7 compatibility
            // Make sure to clean the output buffer before bailing
            while (ob_get_level() >= $this->output_buffer_level) {
                ob_end_clean();
            }

            throw $e;
        } catch (Exception $e) { // TODO: Remove this catch block once PHP 5.x support is no longer necessary.
            // Make sure to clean the output buffer before bailing
            while (ob_get_level() >= $this->output_buffer_level) {
                ob_end_clean();
            }

            throw $e;
        }

        // Lock our response, since we probably don't want
        // anything else messing with our error code/body
        $this->response->lock();
    }
protected function error($err)
    {
        $type = get_class($err);
        $msg = $err->getMessage();

        try {
            if (!$this->error_callbacks->isEmpty()) {
                foreach ($this->error_callbacks as $callback) {
                    if (is_callable($callback)) {
                        if (is_string($callback)) {
                            $callback($this, $msg, $type, $err);

                            return;
                        } else {
                            call_user_func($callback, $this, $msg, $type, $err);

                            return;
                        }
                    } else {
                        if (null !== $this->service && null !== $this->response) {
                            $this->service->flash($err);
                            $this->response->redirect($callback);
                        }
                    }
                }
            } else {
                $this->response->code(500);

                while (ob_get_level() >= $this->output_buffer_level) {
                    ob_end_clean();
                }

                throw new UnhandledException($msg, $err->getCode(), $err);
            }
        } catch (Throwable $e) { // PHP 7 compatibility
            // Make sure to clean the output buffer before bailing
            while (ob_get_level() >= $this->output_buffer_level) {
                ob_end_clean();
            }

            throw $e;
        } catch (Exception $e) { // TODO: Remove this catch block once PHP 5.x support is no longer necessary.
            // Make sure to clean the output buffer before bailing
            while (ob_get_level() >= $this->output_buffer_level) {
                ob_end_clean();
            }

            throw $e;
        }

        // Lock our response, since we probably don't want
        // anything else messing with our error code/body
        $this->response->lock();
    }
protected function error ( $ err ) { $ type = get_class ( $ err ) ; $ msg = $ err -> getMessage ( ) ; try { if ( ! $ this -> error_callbacks -> isEmpty ( ) ) { foreach ( $ this -> error_callbacks as $ callback ) { if ( is_callable ( $ callback ) ) { if ( is_string ( $ callback ) ) { $ callback ( $ this , $ msg , $ type , $ err ) ; return ; } else { call_user_func ( $ callback , $ this , $ msg , $ type , $ err ) ; return ; } } else { if ( null !== $ this -> service && null !== $ this -> response ) { $ this -> service -> flash ( $ err ) ; $ this -> response -> redirect ( $ callback ) ; } } } } else { $ this -> response -> code ( 500 ) ; while ( ob_get_level ( ) >= $ this -> output_buffer_level ) { ob_end_clean ( ) ; } throw new UnhandledException ( $ msg , $ err -> getCode ( ) , $ err ) ; } } catch ( Throwable $ e ) { // PHP 7 compatibility // Make sure to clean the output buffer before bailing while ( ob_get_level ( ) >= $ this -> output_buffer_level ) { ob_end_clean ( ) ; } throw $ e ; } catch ( Exception $ e ) { // TODO: Remove this catch block once PHP 5.x support is no longer necessary. // Make sure to clean the output buffer before bailing while ( ob_get_level ( ) >= $ this -> output_buffer_level ) { ob_end_clean ( ) ; } throw $ e ; } // Lock our response, since we probably don't want // anything else messing with our error code/body $ this -> response -> lock ( ) ; }
Routes an exception through the error callbacks

TODO: Change the `$err` parameter to type-hint against `Throwable` once
PHP 5.x support is no longer necessary.

@param Exception|Throwable $err The exception that occurred
@throws UnhandledException      If the error/exception isn't handled by an error callback
@return void
Routes an exception through the error callbacks