【发布时间】:2014-05-06 14:10:38
【问题描述】:
我关注tutorial 并查看Laravel's docs 以注册自定义错误处理程序。
我注册了这个类,然后抛出 MyCustomException,但由于某种原因,它忽略了其中的所有内容,只运行常规的 Exception 类。下面的代码打印出exception 'MyCustomException' with message 'This is NOT the message I want to see' 而不是“这是自定义异常消息”
目前下面的所有代码都只是在一个测试页面上,但我已经尝试在 Exception 之前将类(并将 MyCustomException 声明)注册到 global.php 中,并且我也在 Exception 之后尝试过。没有任何变化。
我也在 MyCustomException 中尝试过 sleep(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);
}
【问题讨论】:
标签: php exception-handling error-handling laravel laravel-4