1

I followed a tutorial and looked Laravel's docs for registering a custom error handler.

I register the class, and throw MyCustomException, but for some reason, it ignores everything in it and just runs the regular Exception class. The code below prints out exception 'MyCustomException' with message 'This is NOT the message I want to see' instead of "This is the custom exception message"

Currently all the code below is just on a test page, but I've tried registering the class (and putting the MyCustomException declaration) into global.php before Exception and I've tried after Exception as well. Nothing changes.

I've tried sleep(10) inside of MyCustomException too, and that doesn't get run; MyCustomException just doesn't get run.

What am I doing wrong?

Edit: in fact, copying and pasting the code from the tutorial results in the same thing as my custom code; the custom exception handler doesn't get run.

class MyCustomException extends Exception {}

App::error(function(MyCustomException $exception) { 
    return "This is the custom exception message.";
});

//Now throw the error and see what comes out
try {
    throw new MyCustomException('This is NOT the message I want to see');
} catch (MyCustomException $e) {
    die($e);
}

2 Answers 2

1

please try like this

throw new MyCustomException('This is NOT the message I want to see');
Sign up to request clarification or add additional context in comments.

3 Comments

So without the try catch{}, it just prints the same thing to the error log instead of to the screen. [2014-03-27 14:26:23] local.ERROR: exception 'MyCustomException' with message 'This is NOT the message I want to see'
It should be printing This is the custom exception message.
I've tried, it printed, "This is the custom exception message".
0

You've probably solved this by now, but what you want is $e->getMessage().

With PHP 5.1+ that will print your exception message.

Docs: http://php.net/manual/en/exception.getmessage.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.