Custom Error Handler
When TMVC_ERROR_HANDLING is set to 1 in index.php, TinyMVC installs two handlers:
- TinyMVC_ErrorHandler() in /sysfiles/plugins/tinymvc_errorhandler.php turns reported PHP notices, warnings and deprecations into exceptions.
- TinyMVC_ExceptionHandler in /sysfiles/plugins/tinymvc_exceptionhandler.php catches uncaught exceptions and errors, writes them to the PHP error log, and displays them in a formatted box.
Customize the TinyMVC handlers
To change how errors are handled or displayed, override the handler files:
- copy tinymvc_errorhandler.php and/or tinymvc_exceptionhandler.php from /sysfiles/plugins/ to /myapp/plugins/, keeping the same file names
- edit the functionality to your liking, keeping the function and class names
TinyMVC looks in /myapp/plugins/ (and /myfiles/plugins/) before /sysfiles/plugins/, so your copies are used instead of the built-in ones, and they survive upgrades of /sysfiles/.
Use your own handlers
To handle errors entirely on your own, set TMVC_ERROR_HANDLING to 0 in index.php and register your handlers before TinyMVC runs:
define('TMVC_ERROR_HANDLING',0);
set_exception_handler(function($e) {
error_log($e->getMessage());
echo 'Sorry, something went wrong.';
});