Download the PHP package rammewerk/error-handler without Composer
On this page you can find all versions of the php package rammewerk/error-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rammewerk/error-handler
More information about rammewerk/error-handler
Files in rammewerk/error-handler
Package error-handler
Short Description Simple class to manage and normalize PHP errors
License MIT
Homepage https://rammewerk.com
Informations about the package error-handler
Rammewerk ErrorHandler
A simple and flexible way to handle and manage errors and exceptions in your PHP application.
- PHP errors are turned into exceptions by default.
- You can register multiple closures to handle your errors.
- No other dependencies - small size - 1 file only.
Installation
Usage
The error handler should be registered early in your application to ensure they capture any issues that might occur from the outset. If registered late, initial errors might go uncaught. Early registration also promotes structured error management, facilitating easier debugging and maintenance.
There are basically no difference between the log
and report
. Log closures will be called first, then the
reports. So you can add different log
handlers at later point in script, even though an earlier registered report
closure might be used to exit PHP.
log
closures are called in the order they got registered. reports
are called the in reverse order. So you can early
in your application add a general message and then later on add new reports to handle different scenarios the handler
calls the "general" error report.
Why use Rammewerk ErrorHandler?
PHP will either throw exceptions - which are intended to be caught - or print Errors which are generally unrecoverable.
But instead of having to deal with both exceptions and errors, we convert errors so you only have to deal
with exceptions. No more @file_get_contents
just nice and neat try/catch.
Uncaught exceptions will be given to your log
and report
closures.
Many other frameworks or libraries are way more advanced, and comes with loads of functions. This ErrorHandler is simple by design - you decide how to handle your uncaught exceptions and errors.
Tips
- Add the ErrorHandler class as early in your application as possible.
- Add
log
andreport
closure at any point you want. TheErrorHandler
will only call these closures if the exception occurred after the registered closure. So, consider addinglog
andreport
closures as soon as possible. - You can add multiple
log
andreport
closures.log
will be called beforereport
closures. - If you want to remove previous registered closures - set the second argument as true in
log
orreport
. Example:$error->log( $closure, true )
. This can be useful if you want to replace logging after calling other dependencies at a later point in your scripts.
Example
Handle different type of exceptions
report
and log
closures handle any Throwable
exceptions. To distinguish between exception types, incorporate
an instanceOf
check within the closure.