Techno WeBlog

blogging about tech, the tech, and everything tech, for techno addicts!

Join Techno Google group

PHP Custom Error Messages

This is a continuation to my post PHP Magic Constants.
Here I would like to demonstrate a real time example of magic constants.

I am going to write a user function for generating a user-level error/warning/notice message.

function myErrorFunction($error_message,$line,$file)
{
if($error_message!='')
{
$error_string = "User Error : {$error_message} in
{$file} on line number {$line}";
echo $error_string;
die();
}

}

myErrorFunction('test error message',__LINE__,__FILE__);


Now, you can call this function any where in your
script. It should print the error message as follows.

User Error : test error message in H:\test\ccodlib\test.php on line number 12


In the above function,
• die() is a portable way of causing the program to crash.
• __FILE__ is replaced (during compilation) with the name of the file containing the code (as a string).
• __LINE__ is replaced (during compilation) with the current line number (as an integer constant).

------------------

you can also achieve the above functionality by using the built in function “Trigger_error()” provided by PHP.

posted by Jansan John @ 8:02 AM,
Labels : DiggIt!  |   Del.icio.us


0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home

Google

Archives

Previous Posts

Links