Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to handle default error in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 310
    Comment on it

    We can handle default error in PHP in a very simple way. This can be done by sending an error message with its filename, error line number and a message that describes the error to the browser. Error handling plays an important role whenever we make any php script or any php web application.,

    Below you can check some error checking methods in PHP -->

    1. Simple "die()" statements. Custom
    2. errors and error triggers. Error
    3. reporting.

    1- Using the die() function

    <?php
    if(!file_exists("hello.txt")) {
      die("File is not found");
    } else {
      $file=fopen("welcome.txt","r");
    }
    ?> 
    

    2- Custom Error Handler We can create a custom error handlerfor handling the error. We simply create a function that can be called whenever an error occurs.

    error_function(error_level,error_message,
    error_file,error_line,error_context) 
    

    3-Error Report These error report are having user-defined error handler that can be used for default error handing in PHP:

    function customError($errno, $errstr) {
      echo "<b>Error:</b> [$errno] $errstr<br>";
      echo "Ending Script";
      die();
    } 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: