School of Computing  |  Napier  |  Cisco  |  SFC  |  NOS  |  Code |  Old page


PHP - Error handling

In PHP, and error in the parsing of the PHP script will cause an error, and the parser will abort. If you want to handle the error, it is a good idea to add an error handling routing. This is set using the set_error_handler() function, as shown next.

PHP

Executed Code

Generating an error:
<?php
set_error_handler("CustomErrorHandler");
?>
<?php
$val=1/0; // divide-by-zero error
?>

An error has occurred

Error number: 2
Description: Division by zero
Script name: E:\kunden\homepages\29\d390184582\www\php_error.php
Line number: 128
 
Error handling function:
<?php
function CustomErrorHandler($errNumber, $errDescription, $errFile, $errLine)
{
print "<H2>An error has occurred";
print "<P>Error number: $errNumber";
print "<P>Description: $errDescription";
print "<P>Script name: $errFile";
print "<P>Line number: $errLine";
}
?>
 
 

 

 

 



School of Computing  |  Napier  |  Cisco  |  SFC  |  NOS  |  Code |  Old page

Page maintained by bill