Skip to content

Errors and Exceptions

IT Notes → PHP @ December 22, 2020

  • Error is PHP inbuilt whereas Exceptions are thrown. Exceptions are objects.

 

  • Types of error:
    • Compile Time Errors – Cannot be trapped.
    • Fatal Errors – Cannot be trapped.
    • Recoverable Errors – Can be handled.
    • Warnings – Do not halt execution.
    • Notices – Do not halt execution.
  • Error reporting tells what errors to report and display_errors and log_errors will tell how to report.
  • @ – Error control operator.
  • Instead of writing try catch blocks throughout the code you can write set_error_handler(“fn”); with the function fn being passed the error parameters. This function will handle all errors as exceptions.
  • set_error_handler("customError");
    function customError($errno, $errstr);
  • Exception is the base class provided by PHP and we can extend it.
  • Throw throws an exception.
  • PHP allows us to define a catch-all function that is automatically called whenever an exception is not handled. This function is set up by calling set_exception_handler();
  • function handleUncaughtException($e)
    {
    echo $e->getMessage();
    }

     

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x