Php error handling code allow you to show custom error message to the user instead of the default php error message. It is very important to show an error message to the users.
Using the die() function
The die()
function is used to generate the error message if the script doesn’t find the true result.
Example:
[php]<?php
if(!file_exists("welcome.txt")) {
die("File not found");
} else {
$file=fopen("welcome.txt","r");
}
?>[/php]
Code explanation:
In the above code we are trying to open the welcome.txt file by using the file_exists function. If it doen’t find the file on the server then it will generate the error message