symfony - 如何在 Symfony 2 中模拟 500 错误

标签 symfony

我想知道如何在 Symfony 2 中模拟 500 错误。

我一直在阅读this post在哪里 募集 建议抛出异常

throw new sfException('Testing the 500 error');



在 Symfony 1.4 中。

我一直把这段代码放在我的
\store\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\Controller\ExceptionController.php

但我得到了 fatal error

Class 'Symfony\Bundle\TwigBundle\Controller\sfException' not found in /home/notroot/www/store/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php on line 49`



第 49 行指的是我添加的异常代码。

我的问题是,如果在 Symfony 2 中强制出现 500 错误,抛出异常是否仍然可行,如果可以,我应该把这个异常放在哪里?

如果这不再可行,我将如何测试错误 500?

最佳答案

你可以做:

throw new Symfony\Component\HttpKernel\Exception\HttpException(500, "Some description");

关于symfony - 如何在 Symfony 2 中模拟 500 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14284638/

相关文章:

postgresql - 在 Doctrine2 中配置原生 Point PostgreSQL 类型

javascript - 4 FOSJSRouting 回调=fos.Router.setData & 仅在生产中找不到路由

forms - Symfony2 表单 : Changing the default prefix in Form Labels

symfony - 在 Twig 中本地化日期间隔

Symfony2 composer.json "repositories"— 是什么驱动了获取的版本?

php - Symfony2 模板 renderResponse 导致 CPU 使用率飙升

php - 如何在 PHP 中实现多层架构

symfony - 将 Doctrine 连接到 memcached 池

api - Google Analytics API - 与 Symfony2 集成

php - 与 Doctrine Symfony 的条件关系