Search PPTs

Thursday, July 25, 2013

PPT On PHP Error and Exception Handling

Presentation On PHP Error and Exception Handling
Download

PHP Error and Exception Handling Presentation Transcript:
1.PHP Error and Exception Handling

2.Error handling is the process of catching errors raised by your program and then taking appropriate action. If you would handle errors properly then it may lead to many unforeseen consequences.
Its very simple in PHP to handle an errors.

3.Using die() function:
While writing your PHP program you should check all possible error condition before going ahead and take appropriate action when required.
Try following example without having /tmp/test.xt file and with this file.

4.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.
?>

5.This way you can write an efficient code. Using abive technique you can stop your program whenever it errors out and display more meaningful and user friendly meassage.

6.Defining Custom Error Handling Function:
You can write your own function to handling any error. PHP provides you a framwork to define error handling function.
This function must be able to handle a minimum of two parameters (error level and error message) but can accept up to five parameters (optionally: file, line-number, and the error context):

7.Syntax
error_function(error_level,error_message, error_file,error_line,error_context);

8.Possible Error levels
These error report levels are the different types of error the user-defined error handler can be used for. These values cab used in combination using | operator

9.All the above error level can be set using following PHP built-in library function where level cab be any of the value defined in above table.
int error_reporting ( [int $level] )

10.Following is the way you can create one error handling function:
    Function handleError($errno, $errstr,$error_file,$error_line)
     {
    echo "Error: [$errno] $errstr - $error_file:$error_line"; echo "
";
    echo "Terminating PHP Script";
    die();
     }
    ?>

No comments:

Related Posts Plugin for WordPress, Blogger...

Blog Archive