The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

catching fatal error

lalop's Avatar

lalop

17 Sep, 2013 07:51 AM

Hello,
I'm trying to work on a way to catch fatal error.
I'm trying to do that using register_shutdown_function.
I can log error but I don't find a way to send the error template to the user.
Here is my code :

    register_shutdown_function(function() use($app){
    
    if (null === $lastError = error_get_last()) {
        return;
    }
    $errors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_STRICT);
    if (in_array($lastError['type'], $errors)) {
        $e = new ErrorException(
            @$lastError['message'], @$lastError['type'], @$lastError['type'],
            @$lastError['file'], @$lastError['line']
        );
        $app->getLog()->fatal($e);
        ob_get_clean();
        $app->error($e);
    }
    
    });

Doing so I get Fatal error: Uncaught exception 'Slim\Exception\Stop'
So how can I restart the app ?
And what do you think of this method to catch uncaught errors ?

  1. 1 Posted by kevin on 16 Oct, 2015 08:23 PM

    kevin's Avatar

    I've the same problem. Did you find a solution?

  2. 2 Posted by lalop on 16 Oct, 2015 09:16 PM

    lalop's Avatar

    not really sorry, but It seems that php7 solves this.

  3. 3 Posted by largo on 08 Jul, 2016 02:00 PM

    largo's Avatar

    Under PHP7, you can catch throwable Exceptions
    V: Slim Framework 2

     try {
      $app->run()
     }
      catch (\Throwable $e) {
       echo 'error'; 
     }
    

    The problem is, that you can't render the normal error template that way.... :(
    Not sure If you can do that without changing the framework.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac