Error handling is very important in every programming language. PHP uses the trigger to print the error in a program. The example statement is given below:
If ($height_of_door > $height_of_house)
{ trigger_error(“Impossible condition”,E_USER_ERROR); }
The E_USER_ERROR in the statement tells PHP that the condition is an error. Impossible condition is a string message which is displayed when an error is encountered. If the condition comes out to be true then the following message is displayed:
Fatal error: Impossible condition
E_USER_WARNING or E_USER_NOTICE can be used instead of E_USER_ERROR, to have PHP treat the condition as a warning or notice. Own statements can be written to perform error handling actions such as send a message, log a message or stop the script.
For example:
if ($height_of_door > $height_of_house)
{
echo “This is impossible<br>”;
exit();
}
If $height_of_door is larger than $height_of_house, the message is echoed, and exit() stops the script.
Die statement can be used to display an error message when a function fails.
0 comments:
Post a Comment