ErrorHandler.php
public static function exception($exception)
    {
        try {

            // Empty output buffers
            while(ob_get_level() > 0) ob_end_clean();

            // Get exception info
            $error['code']    = $exception->getCode();
            $error['message'] = $exception->getMessage();
            $error['file']    = $exception->getFile();
            $error['line']    = $exception->getLine();

            // Determine error type
            if ($exception instanceof \ErrorException) {
                $error['type'] = 'ErrorException: ';
                $error['type'] .= in_array($error['code'], array_keys(ErrorHandler::$levels)) ? ErrorHandler::$levels[$error['code']] : 'Unknown Error';
            } else {
                $error['type'] = get_class($exception);
            }

            // Write to log
            ErrorHandler::writeLogs("{$error['type']}: {$error['message']} in {$error['file']} at line {$error['line']}");

            // Send headers and output
            @header('Content-Type: text/html; charset=UTF-8');

            if (DEVELOPMENT) {

                $error['backtrace'] = $exception->getTrace();

                if ($exception instanceof \ErrorException) {
                    $error['backtrace'] = array_slice($error['backtrace'], 1); //Remove call to error handler from backtrace
                }

                $error['backtrace']   = self::formatBacktrace($error['backtrace']);
                $error['highlighted'] = self::highlightCode($error['file'], $error['line']);

                @header('HTTP/1.1 500 Internal Server Error');
                include 'views/exception.php';

            } else {

                @header('HTTP/1.1 500 Internal Server Error');
                include 'views/production.php';

            }

        } catch (Exception $e) {

            // Empty output buffers
            while(ob_get_level() > 0) ob_end_clean();

            echo $e->getMessage() . ' in ' . $e->getFile() . ' (line ' . $e->getLine() . ').';
        }

        exit(1);
    }
public static function exception($exception)
    {
        try {

            // Empty output buffers
            while(ob_get_level() > 0) ob_end_clean();

            // Get exception info
            $error['code']    = $exception->getCode();
            $error['message'] = $exception->getMessage();
            $error['file']    = $exception->getFile();
            $error['line']    = $exception->getLine();

            // Determine error type
            if ($exception instanceof \ErrorException) {
                $error['type'] = 'ErrorException: ';
                $error['type'] .= in_array($error['code'], array_keys(ErrorHandler::$levels)) ? ErrorHandler::$levels[$error['code']] : 'Unknown Error';
            } else {
                $error['type'] = get_class($exception);
            }

            // Write to log
            ErrorHandler::writeLogs("{$error['type']}: {$error['message']} in {$error['file']} at line {$error['line']}");

            // Send headers and output
            @header('Content-Type: text/html; charset=UTF-8');

            if (DEVELOPMENT) {

                $error['backtrace'] = $exception->getTrace();

                if ($exception instanceof \ErrorException) {
                    $error['backtrace'] = array_slice($error['backtrace'], 1); //Remove call to error handler from backtrace
                }

                $error['backtrace']   = self::formatBacktrace($error['backtrace']);
                $error['highlighted'] = self::highlightCode($error['file'], $error['line']);

                @header('HTTP/1.1 500 Internal Server Error');
                include 'views/exception.php';

            } else {

                @header('HTTP/1.1 500 Internal Server Error');
                include 'views/production.php';

            }

        } catch (Exception $e) {

            // Empty output buffers
            while(ob_get_level() > 0) ob_end_clean();

            echo $e->getMessage() . ' in ' . $e->getFile() . ' (line ' . $e->getLine() . ').';
        }

        exit(1);
    }
Handles uncaught exceptions and returns a pretty error screen.

@param Exception $exception An exception object