onFatalException Details

When Grav fires the onFatalException event, I would like to send myself a notice of the error with details. The notification works, but I can’t figure out where to grab exception details. Any ideas?

public static function getSubscribedEvents() {
    return [
        'onPageNotFound' => ['sendAlert', 0],
        'onFatalException' => ['sendAlert', 0]

 * Convert error hook into alert mesage
 * Route message to alert mechanism (currently Slack)
 * @param Event $event
 * @param string $hook
public function sendAlert(Event $event, $hook) {
    $url = $this->slackFriendlyUrl($this->grav['uri']->url);
    if ($hook === "onPageNotFound") {
        $message = "```404: " . $url  . "```";
    } elseif ($hook === "onFatalException") {
        $message = "@channel: Grav Error :warning: ```Fatal Exception:
" . $url . "
" . $exception_string? . "```";
    } else {
        $message = "@channel: Grav Error :warning: ```Undefined Error:
" . $url . "```";


To be honest i’ve not tried adding additional handlers for this event as the only place it’s currently used (that I know of) is in the problems plugin. I’m not 100% sure that even works in that instance. I think Whoops might be handling the exception before this event is even fired.

Please create an issue for this onFatalException() event here: https://github.com/getgrav/grav/issues

Ok, i tested this a bit today. It is working fine after all. I created an onFatalExceptionevent in my testing plugin, and debugged it. It went in there fine. I was able to log out a message no problem. What I have added is the exception is now passed to the event so you can actually know what the exception was that cause the event in the first place: https://github.com/getgrav/grav/commit/d42786484f10a9ae23820400ace35867474498e0

Then you can use it like this:

    public function onFatalException(Event $e)
        $exception = $e['exception'];
        $this->grav['log']->addCritical(">>> " . $exception->getMessage());

Awesome, I made those changes and it does exactly what I want it to. Also, thanks for working on the weekend.

I see that commit is on the develop branch, are you planning on adding those index.php changes to an upcoming release?

Yes, they will be in the next RC release.

Perfect. Thanks.