Php Laravel自定义异常处理程序未运行

Php Laravel自定义异常处理程序未运行,php,exception-handling,error-handling,laravel,laravel-4,Php,Exception Handling,Error Handling,Laravel,Laravel 4,我遵循了一个命令,并寻找注册一个自定义错误处理程序 我注册该类,并抛出MyCustomException,但出于某种原因,它忽略了其中的所有内容,只运行常规异常类。下面的代码打印出异常“MyCustomException”,并显示消息“这不是我想看到的消息”,而不是“这是自定义异常消息” 目前,下面的所有代码都只是在一个测试页面上,但我尝试在异常之前将类注册(并将MyCustomException声明)到global.php中,也尝试在异常之后注册。没有什么变化 我也尝试过在MyCustomEx

我遵循了一个命令,并寻找注册一个自定义错误处理程序

我注册该类,并抛出MyCustomException,但出于某种原因,它忽略了其中的所有内容,只运行常规异常类。下面的代码打印出异常“MyCustomException”,并显示消息“这不是我想看到的消息”,而不是“这是自定义异常消息”

目前,下面的所有代码都只是在一个测试页面上,但我尝试在异常之前将类注册(并将MyCustomException声明)到global.php中,也尝试在异常之后注册。没有什么变化

我也尝试过在MyCustomException中睡眠(10),但没有成功;MyCustomException无法运行

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);
}
我做错了什么

编辑:事实上,复制和粘贴教程中的代码会产生与我的自定义代码相同的结果;自定义异常处理程序无法运行

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);
}
请像这样试试

throw new MyCustomException('This is NOT the message I want to see');

您现在可能已经解决了这个问题,但您需要的是
$e->getMessage()

使用PHP5.1+将打印异常消息


文档:

因此,如果没有
try catch{}
,它只会将相同的内容打印到错误日志中,而不是屏幕上<代码>[2014-03-27 14:26:23]本地。错误:异常“MyCustomException”并显示消息“这不是我想看到的消息”它应该正在打印
这是自定义异常消息。
我尝试过,它打印了“这是自定义异常消息”。