-
Notifications
You must be signed in to change notification settings - Fork 10
Errors
Stefano Azzolini edited this page Feb 22, 2016
·
1 revision
The Errors module allow you catch and manage errors.
You can start the error handler via the capture method.
Errors::capture();
From now on errors are converted to ErrorExceptions and routed to the handler which dispatches them in core.error.* events, filtered by kind.
You can bind directly to these events via the special Errors::on* methods.
Event::on('core.error.warning',function($exception){
syslog(LOG_WARNING,$exception->getMessage());
});
Preferred shortcut :
Errors::onWarning(function($exception){
syslog(LOG_WARNING,$exception->getMessage());
});
These are the error mapping rules:
| ErrorType | Gravity | Event | Method |
|---|---|---|---|
E_NOTICE |
Informational | core.error.notice |
Errors::onNotice |
E_USER_NOTICE |
Informational | core.error.notice |
Errors::onNotice |
E_STRICT |
Informational | core.error.notice |
Errors::onNotice |
E_WARNING |
Warning | core.error.warning |
Errors::onWarning |
E_USER_WARNING |
Warning | core.error.warning |
Errors::onWarning |
E_USER_ERROR |
Fatal | core.error.fatal |
Errors::onFatal |
Every error will be also dispatched via the core.error event. You can bind directly to this event via the Errors::onAny method.
If a single error handler returns
true, the current error will be silenced and not propagated any more.
Errors can be displayed with various formats:
| Modes | Description | Example |
|---|---|---|
Errors::SIMPLE |
Prints the error message in plain text | Notice: undefined variable x. |
Errors::HTML |
Prints the error message wrapped in html | <pre class="app error"><code>Notice: undefined variable x.</code></pre> |
Errors::SILENT |
Don't print anything | |
Errors::JSON |
Print a JSON string of an error envelope | {"error":"Notice: undefined variable x."} |
Errors::mode(Errors::HTML);
Core is maintained by using the Semantic Versioning Specification (SemVer).
Copyright 2014-2016 Caffeina srl under the MIT license.
http://caffeina.com