Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Error handling php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 247
    Comment on it

    It is basically the process  of catching the error that occurred in the program and then taking an appropriate action.

    It is very simple to handle the error in php.

    While writing the program we should check all the possible error condition before the executing.

    ex

    <?php
       if(!file_exists("/tmp/test.txt")) {
          die("File not found");
       }else {
          $file = fopen("/tmp/test.txt","r");
          print "Opend file sucessfully";
       }
       // Test of the code here.
    ?>

    This is the way to find the error and display a message whenever error occur.

    We can write our own error catching function

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

    This is the way to create an error handling program

    <?php
       function handleError($errno, $errstr,$error_file,$error_line) {
          echo "<b>Error:</b> [$errno] $errstr - $error_file:$error_line";
          echo "<br />";
          echo "Terminating PHP 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: