PHP Basic Errors - Code

PHP Sent E-MAIL From PHP Previous Next PHP Strings


A error handler in PHP is used to catch errors in a program and then taking appropriate action.

Using an error handler makes the programmer write an efficient code and at the same time display more meaningful and user friendly messages when errors occurs.

PHP has some very simple error handling functions.

Die() Function

The die() function is used to check the code for errors, display appropriate error messages and exit the script.

For example, in the following program, the code checks to see if the text1.txt file is found.

If the file is not found, it will displays an appropriate error messages and exit the script.

Filename: php / die-function.php


Code
 
<?php;
if(!file_exists("text1.txt")){
die("File not found");
}else{ 
$file = fopen("text2.txt","r");
echo "File opened sucessfully.";
}
?>

Running Step.


Type Url - https://localhost/php/die-function.php


Tags: PHP Basic Errors PHP Code Programming Language


Was this helpful ?

Related Code