gpt4 book ai didi

php - 如何在 PHP 中记录未捕获的异常?

转载 作者:可可西里 更新时间:2023-10-31 22:10:06 24 4
gpt4 key购买 nike

我已经找到了如何将错误转换为异常,如果它们没有被捕获,我会很好地显示它们,但我不知道如何以有用的方式记录它们。简单地将它们写入文件不会有用,是吗?如果您还不知道导致异常的原因,您会冒险访问数据库吗?

最佳答案

你可以使用 set_error_handler设置自定义异常以记录您的错误。我个人会考虑将它们存储在数据库中,因为默认的异常处理程序的回溯可以提供有关导致它的原因的信息 - 如果数据库处理程序触发了异常,这当然是不可能的。

你也可以使用 error_log记录你的错误。它可以选择消息目的地,包括:

Quoted from error_log

  1. PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to. This is the default option.
  2. Sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used.
  3. Appended to the file destination . A newline is not automatically added to the end of the message string.

编辑:markdown 有下划线的 noparse 标签吗?

关于php - 如何在 PHP 中记录未捕获的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com