Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

It's not very elegant, but
die('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
 
Share this answer
 
Comments
rashidfarooq 14-May-11 1:23am    
I know that this is a method of error displaying. But I want to use an elegant way. Suppose, I have written my php code before the body section of my web page, But I want to show this error some where in body section, then how this die("message") function can help me, because it will truncates every thing after it.
Peter_in_2780 14-May-11 2:19am    
There are two options that I can think of.
1. die() takes a string, so you could put a LOT of stuff in the string before and after your actual error message.
2. CSS means you can put stuff "out-of-order" on the page, so the rest of the page could be already output, then the die() just fills in a particular <div> or something like that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900