我可以重新定义PHP显示未捕获异常的方式吗?

我可以重新定义PHP显示未捕获异常的方式吗?,php,exception,exception-handling,Php,Exception,Exception Handling,PHP中的正常抛出和未抛出异常将产生类似于以下内容的输出: Fatal error: Uncaught exception 'Exception' with message 'Insufficient permissions or something' in /home/codemonkey/foo/bar/File.php:143 Stack trace: #0 /home/codemonkey/dev/foo/bar/SomeOtherFile.php(85): foo\bar\File::

PHP中的正常抛出和未抛出异常将产生类似于以下内容的输出:

Fatal error: Uncaught exception 'Exception' with message 'Insufficient permissions or something' in /home/codemonkey/foo/bar/File.php:143 Stack trace: #0 /home/codemonkey/dev/foo/bar/SomeOtherFile.php(85): foo\bar\File::fromUpload(Array) #1 /home/codemonkey/dev/foo/bar/OmniDataFileImport.php(35): foo\bar\OmniDataFileImport->performFileImportLogic() #2 [internal function]: foo\bar\OmniDataFileImport->post(Object(Request), false) #3 /home/codemonkey/dev/foo/vendor/tonic/lib/tonic.php(654): call_user_func_array(Array, Array) #4 /home/codemonkey/dev/foo/dispatch.php(22): Resource->exec(Object(Request)) #5 {main} thrown in /home/codemonkey/dev/foo/broadnet/files/File.php on line 143 致命错误:未捕获异常“exception”,在/home/codemonkey/foo/bar/File.php:143中显示消息“权限不足或其他问题” 堆栈跟踪: #0/home/codemonkey/dev/foo/bar/SomeOtherFile.php(85):foo\bar\File::fromUpload(数组) #1/home/codemonkey/dev/foo/bar/OmniDataFileImport.php(35):foo\bar\OmniDataFileImport->performFileImportLogic() #2[内部函数]:foo\bar\OmniDataFileImport->post(对象(请求),false) #3/home/codemonkey/dev/foo/vendor/tonic/lib/tonic.php(654):调用用户函数数组(数组,数组) #4/home/codemonkey/dev/foo/dispatch.php(22):资源->执行(对象(请求)) #5{main} 在第143行的/home/codemonkey/dev/foo/broadnet/files/File.php中抛出 消息和堆栈跟踪很酷,但我真的想了解更多信息。出于这个原因,我想用更多的信息来扩展异常,比如局部变量及其值。问题是PHP可能仍然会输出相同的上述信息,但会使用文本“uncaughtexception'MyException'”

我可以重写PHP显示未捕获异常的方式吗?我记得读过一篇关于PHP中的函数的文章,您可以将其设置为备份,以捕获所有未捕获的异常。也许我可以使用这个功能来格式化我自己的消息并终止这个过程

感谢您提供有关您要查找的主题的所有有用信息


但是,您无法检索局部变量等。除非您使用不适用于生产系统的调试扩展,否则PHP的错误处理/调试相当糟糕。

如果不在每个
抛出
站点编写代码,您就无法在库存PHP上获取局部变量;由不受您控制的代码引发的异常也不会有局部变量,对此您无能为力。但我仍然可以用反射做一些很酷的事情…:-)没问题。由于我是抛出异常的人,至少我可以标记任何我喜欢的额外信息并正确地显示它。谢谢