Profile Picture
IT Made Easy
The site provides some rough IT Notes that make your life easier. The site currently has notes on HTML, CSS, Regex, OOPS, JS, JQuery, PHP, Java, ASP.NET, C#, Database, Linux, URL Rewrite, SEO, Project Management and Hosting. Please do share this site if you like.

Errors and Exceptions

Next
Next
  • Error is PHP inbuilt whereas Exceptions are thrown. Exceptions are objects and unhandled is fatal
  • Types of errors
  1. Compile Time Errors - Cannot be trapped
  2. Fatal Errors - Cannot be trapped
  3. Recoverable Errors - Can be handled
  4. Warnings - Do not halt execution
  5. 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();

}

IT Notes

by VinodSebastian



IT Downloads


Catalogue