The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Call Slims custom error handler within php error_handler/ exception_handler

Marc's Avatar


29 May, 2013 10:40 AM

Hi there,

I have a problem with calling the Slim error handler within the PHP error_- and excepion_handler. My basic problem is, that next to Slim I use Pimple, SwiftMailer,... and if there is any error with initialize the libraries there is an exception or error. And I want to log this error and route the user to Slims error page.

So here is my code:
$app->error(function ($e) use ($app) {
    echo '<h1>ERROR!</h1>';

function myErrorHandler ($errorCode, $errorMessage, $errorFile, $errorLinenumber) {
    global $app;

throw new Exception("Error Processing Request", 1);

$app -> run();
With this I got an new Slim Exception:
Fatal error: Uncaught exception 'Slim\Exception\Stop' in \Slim.php on line 927

Too bad :( If I invoke the 'throw new Exception("Error Processing Request", 1);' in an route, everything works fine. But not in my handler. If I use $app->redirect('/'); there is the same problem.

Thanks in advance

  1. 1 Posted by Marc on 29 May, 2013 12:00 PM

    Marc's Avatar

    Okay, one other question: in the documentation, there is written 'A Slim application only handles errors and exceptions generated inside the Slim application;'
    But I want that Slim handles ALL errors (inside and outside). How can I do this?

  2. Support Staff 2 Posted by Brian Nesbitt on 30 May, 2013 03:21 AM

    Brian Nesbitt's Avatar

    Slim doesn't setup its error handlers until you call run() on the app. Before that the error handling is up to you.

    What if you did something like:

    function handleError() {
       echo '<h1>ERROR!</h1>'; 
    function myErrorHandler ($errorCode, $errorMessage, $errorFile, $errorLinenumber) { 
    throw new Exception("Error Processing Request", 1);
    $app -> run();

    This way you can run the same error handler before slim and after slim?!?

  3. 3 Posted by Marc on 30 May, 2013 06:06 AM

    Marc's Avatar

    Hi Brian,
    thanks for your reply. Yeah I would use your example code. Slim uses a Middleware and a Try Catch Block for getting errors. All errors are converted to an exception. And all exceptions are caught by PrettyExceptions Middleware. So your example would be the best way to handle all errors the same way. Thanks!

  4. 4 Posted by hema on 05 Apr, 2016 08:22 AM

    hema's Avatar

    good Shareit apk is certainly 200 situations faster than Bluetooth, the highest swiftness will go up to 20M/h. Shareit for android wirelessly obtain the gadgets linked straight. nice.

  5. 5 Posted by dhara on 21 Apr, 2016 06:14 AM

    dhara's Avatar

    good we advise BlueStacks. Comply with the total information in The software is usually extremely very much well-known in the Yahoo Take up Shop. nice.

  6. 6 Posted by mike on 26 May, 2016 06:13 PM

    mike's Avatar

    effective information i like your page. best app which you can install and use easily on pc and other devices.

  7. 7 Posted by lewismichael230... on 26 Nov, 2016 06:06 AM

    lewismichael2301's Avatar

    good The best benefit is that You could see online or you could also download . obtain this application on your Android tool. nice.

  8. 8 Posted by terryjohnterry2... on 28 Dec, 2016 10:08 AM

    terryjohnterry2101's Avatar

    good see limitless movie & video streaming your home windows computer. from the Sports market, like the critical matches. best.

  9. 9 Posted by tank on 11 Mar, 2017 06:15 AM

    tank's Avatar

    good and install things from various other much less Arizona's food is heavily influenced by Mexico, bset.

  10. 10 Posted by johnny on 08 May, 2017 05:43 AM

    johnny's Avatar

    Windows, and Linux. No issues of having iphone app trusting your designer certificate, stay linked to the net.

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


? 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