PHP Error Handling Functions

PHP Error Handling Functions and example that explains how to create user defined error handling functionalists.

Though every programming language offers default error handling methods. You can also write your own error handling functions in PHP.

There is a bit difference between user defined error handling method and a default error handling techniques.

In a default error handling method, program will throw a error message with filename, error message describing the error along with the line
number where error has occurred. But in a user defined error handling you can throw a well defined error message that helps you to find and
rectify error easily.

Given are the types of PHP Error Handling Functions:

  • die() method
  • setting custom error handler and error triggering
  • error reporting

In PHP die( ) method is used to handle simple and basic errors in PHP. For example if your program is not able to find or located any file or variable then it will simply die, instead of sending an error message to user.

Where as a Custom error handler or triggering is used to trigger a error when user is not entering a desirable input.

Error reporting is a method to send an error message to the user. By default PHP sends an error message to user with line number, error message and file names. But in case of using error reporting method you can send a well defined error message to users on entering a wrong data or input.

Go through the given error handling tutorial for example code.

PHP Error Handling Example