gpt4 book ai didi

php - 忽略PHP错误,同时仍打印自定义错误消息

转载 作者:行者123 更新时间:2023-12-03 08:03:03 24 4
gpt4 key购买 nike

所以:

@fopen($file);

忽略任何错误并继续
fopen($file) or die("Unable to retrieve file");

忽略错误,终止程序并打印自定义消息

有没有一种简单的方法可以忽略函数中的错误,打印自定义错误消息而不杀死程序?

最佳答案

通常:

if (!($fp = @fopen($file))) echo "Unable to retrieve file";

或使用您的方式(丢弃文件句柄):
@fopen($file) or printf("Unable to retrieve file");

关于php - 忽略PHP错误,同时仍打印自定义错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/883870/

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