Silex 异常处理程序 [英] Silex Exception handler
本文介绍了Silex 异常处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大问题,我不知道为什么 silex 异常处理程序没有捕获异常?
I have big problem I don't know why exceptions are not catch by silex exception handler ?
我的简单代码如下所示:
My simple Code looks like this:
<?php
use Silex\Application;
use Silex\Provider\ValidatorServiceProvider;
use Silex\Provider\FormServiceProvider;
use Symfony\Component\HttpFoundation\Request;
$app = new Application();
// SPL Logic Exceptions
// Handle other exception as 500 errors
$app->error(function (\Exception $e, $code) {
exit('asd');
});
throw new Exception('test');
return $app;
结果是:
致命错误:未捕获的异常异常",消息为测试"
推荐答案
error
侦听器只能捕获从控制器或 before
中间件中抛出的异常.这是一个有效的例子:
The error
listener is only able to catch exceptions thrown from within a controller or a before
middleware. Here's an example that works:
$app = new Silex\Application();
$app->error(function (\Exception $e, $code) {
exit('asd');
});
$app->before(function ($request) {
throw new Exception('test');
});
$app->run();
这篇关于Silex 异常处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文