- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Errors in PHP7
Prior to version 7, PHP parser used to report errors in response to various conditions. Each error used to be of a certain predefined type. PHP7 has changed the mechanism of error reporting. Instead of traditional error reporting, most errors are now reported by throwing error exceptions.
If error exceptions go unhandled, a fatal error is reported and will be handled like traditional error condition. PHP's error heirarchy starts from Throwable interface. All predefined errors such as ArithmeticError, AssertionError, CompileError and TypeError are classes implementing Throwable iterface. Exception in PHP 7 is also implements Throwable interface.
Throwable interface acts as base for any object that can be thrown via throw statement, including Error and Exception objects. A user defined class can not implement Throwable interface directly. Instead, to declare a user defined exception class, it must extend Exception class.
PHP's exception handling consists of throw, catch, try statements. To raise exception object, there is throw keyword. Thrown exception are processed by catch block. PHP code that is potentially vulnerable for exception is enclosed in try block.
One or more catch blocks may be present to catch different instances of Exception classes. When no exception occurs in try block, normal execution will continue after last catch block. However, when exception is thrown inside try block, instead of nest statement being executed, PHP tries to find a catch block tht matches type of exception to be handled. If no matching catch block is defined, PHP parser will report Fatal error with Uncaught Exception message.
You may also provide finally block either after or instead of catch blocks. Code in finally block will always be executed, irresepective of whether exception occurs inside try block or not.
- PHP Types of Errors
- How to display errors in PHP file?
- Errors in C/C++
- Difference between Compile Time Errors and Runtime Errors in C Program
- Database Handling Errors in Python
- Errors within Perl Modules
- What is the difference between compile time errors and run time errors in Java?
- Are Python Exceptions runtime errors?
- Handling errors in SAP GUI Scripting code
- How to handle Geolocation errors in HTML5?
- How to create custom errors in Golang