【发布时间】:2016-12-20 17:33:14
【问题描述】:
我在 Symfony 文档中了解到内核事件:http://symfony.com/doc/current/components/http_kernel.html
上面写着:As you've seen, you can create and attach event listeners to any of the events dispatched during the HttpKernel::handle() cycle
没问题,我可以创建一个自定义异常监听器并监听内核事件。
但是我怎样才能在启动过程中发现潜在的错误(因为没有调用任何监听器):
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
if (false === $this->booted) {
$this->boot(); // Error can be thrown
}
return $this->getHttpKernel()->handle($request, $type, $catch);
}
例如,如果我提供了对数据库 (DriverException) 的错误访问权限,我可能会遇到这种错误。
在开发模式下,这没关系,因为我有一个默认错误处理程序 DebugBundle,但在生产中它是一个白屏。
我该如何正确处理?
【问题讨论】:
-
您可以在 web/app.php 中的代码周围放置一个 try/catch 块。不完全确定您可以对任何捕获的异常做什么,但至少您可以捕获它们
标签: php symfony exception events kernel