diff --git a/base.php b/base.php index f7a16f9..3cead7c 100644 --- a/base.php +++ b/base.php @@ -101,3 +101,101 @@ if(!empty($cphp_config->autoloader)) spl_autoload_register('cphp_autoload_class'); } + +set_exception_handler(function($e){ + /* Intentionally not using the templater here; any inner exceptions + * cause serious debugging issues. Avoiding potential issues by just + * hardcoding the response here, with no code that could raise an + * exception. */ + $exception_class = get_class($e); + $exception_message = $e->getMessage(); + $exception_file = $e->getFile(); + $exception_line = $e->getLine(); + $exception_trace = $e->getTraceAsString(); + + error_log("Uncaught {$exception_class} in {$exception_file}:{$exception_line} ({$exception_message}). Traceback: {$exception_trace}"); + + switch(strtolower(ini_get('display_errors'))) + { + case "1": + case "on": + case "true": + $error_body = " +
+ An uncaught {$exception_class} was thrown, in {$exception_file} on line {$exception_line}. +
++
+ +{$exception_trace}+
Important: These errors should never be displayed on a production server! Make sure that display_errors is turned off in your PHP configuration, if you want to hide these tracebacks.
+ "; + break; + default: + $error_body = " ++ Something went wrong while creating this page, but we're not yet quite sure what it was. +
++ If the issue persists, please contact the administrator for this application or website. +
+ "; + break; + } + + echo(" + + + +