Home > PHP > PHP Error handling

PHP Error handling

October 15th, 2011 Leave a comment Go to comments

Error handling is very important in any programming languages. When error occurs the error message with filename ,line no is displayed on the browser. When we are creating scripts the error handling is very important .If our code have not error checking code then our code is not professional.
In PHP there are several methods of error handling.
1:Die(); statement.
2:Custom Errors and error triggers
3:Error Reporting
Die() function:
Die function is the most common function we use in our script for error handling.
e.g
If we want to display a variable from echo statement then we write
echo $variable_name;
?>
If the variable doesn’t exists then a error occur Warning: variable_name is undefined
To avoid such type of warning we use die function
If(isset($varible_name))
{
echo $varible_name;
}
else
{
die(‘Varible Not Found’);
}
?>
This code is more professional than above code fo displaying the eror.But this type of error mechanism is not always efficient So we have some professional mechanism to handle the errors.

Categories: PHP Tags: