Symfony:On Custom Listener在抛出异常时获取代码片段和文件

时间:2017-11-06 08:45:59

标签: php symfony exception-handling httpresponse symfony-3.3

在我的symfony 3.3上抛出异常时,我想覆盖返回的响应。所以我做了自己的事件监听器,因为它说了以下文档:http://symfony.com/doc/current/event_dispatcher.html

但是当我在开发环境中运行它时,我想要获得堆栈跟踪和代码行。我设法使用以下代码获取堆栈跟踪:

$exception = $event->getException();
$exception->getTrace();

但是我如何才能获得提供默认视图抛出的特定异常的片段?

编辑1:进一步说明

我的意思是在默认的异常抛出视图中,我得到一个类似的响应:

<Exception_NAME>

in ^somefile^ as line ^Some Line^

<The php code lines where the exception has been thrown>

in ^another_somefile^ as line ^Some Line^

<The php code lines where the exception has been thrown>

当我在开发环境中运行应用程序时,我希望当Over dev将响应保留在日志文件中或视图本身中时。

0 个答案:

没有答案