如何处理symfony2中的错误并将错误存储在自定义表中


how to handle errors in symfony2 and store error in custom table

如何在symfony2中使用try catch处理错误,并将错误存储在自定义db表中,就像我们在c#中做的那样。

try
{
     // code with exception.
}
catch(Exception ex)
{
    //get the error and store information in table
} 

您可以使用PHP try-catch块来捕获前面提到的异常。你可以看看这个答案:如何在symfony 2中捕获异常?

使用此方法,您可以捕获给定代码块的异常。如果你想在一般情况下捕获所有异常,那么你应该编写一个EventListener类,它将在任何未捕获的异常发生时被触发。

在Symfony2的烹饪书中有一个编写异常处理程序类的示例:如何创建事件侦听器