<commit_before><?php
namespace Thulium;

class Error
{
    static public function exceptionHandler(\Exception $exception)
    {
        self::_handleError($exception->getMessage(), $exception->getTraceAsString());
    }

    static public function errorHandler($errno, $errstr, $errfile, $errline)
    {
        throw new \Exception("$errfile:$errline - $errstr ERRNO($errno)");
    }

    private static function _clearOutputBuffers()
    {
        while (ob_get_level()) {
            ob_end_clean();
        }
    }

    private static function _handleError($errorMessage, $errorTrace)
    {
        Logger::getPanelLogger()->addError($errorMessage, array($errorTrace));
        /** @noinspection PhpIncludeInspection */
        self::_clearOutputBuffers();
        header("HTTP/1.1 500 Internal Server Error");
        require_once(ROOT_PATH . 'application' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'exception.phtml');
    }

    static public function shutdownHandler()
    {
        $error = error_get_last();

        if ($error && $error['type'] & (E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR)) {
            self::errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
        }
    }
}<commit_msg>try...catch in framework exception handler.<commit_after><?php
namespace Thulium;

class Error
{
    static public function exceptionHandler(\Exception $exception)
    {
        self::_handleError($exception->getMessage(), $exception->getTraceAsString());
    }

    static public function errorHandler($errno, $errstr, $errfile, $errline)
    {
        throw new \Exception("$errfile:$errline - $errstr ERRNO($errno)");
    }

    private static function _clearOutputBuffers()
    {
        while (ob_get_level()) {
            ob_end_clean();
        }
    }

    private static function _handleError($errorMessage, $errorTrace)
    {
        try {
            Logger::getPanelLogger()->addError($errorMessage, array($errorTrace));
            /** @noinspection PhpIncludeInspection */
            self::_clearOutputBuffers();
            header("HTTP/1.1 500 Internal Server Error");
            require_once(ROOT_PATH . 'application' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'exception.phtml');
        } catch (\Exception $e) {
            echo "Framework critical error. Exception thrown in exception handler.<br>\n";
            echo "<hr>\n";
            echo "Message: " . $e->getMessage() . "<br>\n";
            echo "Trace: " . $e->getTraceAsString() . "<br>\n";
        }
    }

    static public function shutdownHandler()
    {
        $error = error_get_last();

        if ($error && $error['type'] & (E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR)) {
            self::errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
        }
    }
}
{'fraction_non_alphanumeric': 0.14188267394270124, 'fraction_numerical': 0.0034106412005457027, 'mean_word_length': 2.88476821192053, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7518651', 'n_tokens_mistral': 855, 'n_tokens_neox': 840, 'n_words': 169}