php - 如果发生异常,防止 PHP 回显
问题描述
我注意到 PHPecho
成功地打印字符串,即使在脚本中的某个地方抛出了错误并且没有被处理。例如:
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "started";
throw new Exception("big error");
echo "done";
打印"started"
,即使发生错误。状态码确实是 500,但我不认为显示部分结果适用于所有情况。
使用ob_start()
andob_get_contents()
提供了一些灵活性,但我希望 PHP 提供一个开关,以便在发生错误时将显示设置为无。这个开关存在吗?
解决方案
echo "started"; // <- This will occurs
throw new Exception("big error"); // <- And here the Exception will be thrown
echo "done"; // <- therefore, this line won't be reached
推荐阅读
- c - C字符串赋值后为空
- html - 为什么我的轮播没有加载到我的网页?
- node.js - 反应原生,无法安装expo-cli
- vuex - 如何避免在vue spa中按下后退按钮时为刚刚导航离开的页面获取数据
- c++ - 为什么此代码在 timus 1086 问题中出现运行时错误?
- python - 制作棕褐色图以使其适合我的屏幕的理想范围是多少?
- python - 关于 Django 的博客,用于获取登录用户帖子的查询集
- python-3.x - 如何在 Python 中使用 SAS SWAT 模块更改 CASTable 的 dtype
- javascript - 为 v-for 模板中的加载事件绑定 this
- java - 在java中将一个值缓和到另一个值超时