What is an exception handling ?

Exception handling is used to change the normal flow of the code execution if a specified error (exceptional) condition occurs. This condition is called an exception.
PHP has an exception model similar to that of other programming languages. Exceptions are important and provides a better control over error handling.
<?php
try {
    $error = ‘Always throw this error’;
    throw new Exception($error);
    // Code following an exception is not executed.
    echo ‘Never executed’;
} catch (Exception $e) {
    echo ‘Caught exception: ‘,  $e->getMessage(), “\n”;
}
// Continue execution
echo ‘Hello World’;
?>
prabaweb.in Codelab- programming blog © 2017