显示错误消息的优雅方式是什么? [英] What is the elegant way to show an error message
问题描述
我正在使用PHP和MySQL开发一个站点.我在显示错误消息时遇到了一些麻烦.我在这个站点中使用了很多功能(我已经定义了自己).在函数中很多次,我需要根据特定条件停止函数的执行.退出此功能后,我需要以优雅的方式在网页上显示原因(错误消息).如果我在自己定义的函数中使用die()函数停止执行,则整个过程的其余部分将停止,包括我的网页(HTML).因此,我无法显示错误消息.
当我根据特定条件停止执行函数并从中退出时,如何以优雅的方式显示错误消息.
I am developing a site using PHP and MySQL. I have a little trouble about showing the error messages. I am using so many functions in this site (which I have defined myself). Many times in a function I need to stop the execution of function on the basis of a specific condition. After coming out of this function I need to show the reason (error message) on the web page in an elegant way. If I use the die() function in my own defined function to stop its execution then whole rest of the process stops including my web page (HTML). Thus I am unable to show the error message.
What Should I do to display an error message in an elegant way, when I stop the execution of a function on the basis of a specific condition, and came out of it.
推荐答案
不是很优雅,但是
It''s not very elegant, but
die(''This is a message.'')
将在终止前输出This is a message.
.
这是处理致命但不太可能的错误的相当普遍的技术.
干杯,
彼得
will output This is a message.
before terminating.
This is a fairly common technique for handling fatal but unlikely errors.
Cheers,
Peter
这篇关于显示错误消息的优雅方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!