Throwable errors
A Throwable error is an execution event which disrupts
the normal flow of instructions. When a Throwable error
is
To throw a Throwable error from within PHP code,
use the Tip
The Standard PHP Library (SPL) provides various built-in exceptions. It is also possible to create custom exceptions by extending the Exception class.
It is possible to handle a Throwable error within PHP
by surrounding the code that may throw an error in a Warning
Throwable objects cannot be cloned.
Attempting to clone such an
object throws an Error with the following message:
Global exception handler
It's possible to add a handler for any uncaught
Throwable with
set_exception_handler.
This is similar to wrapping the entire code in a Extending exceptionsA user-defined exception can be defined by extending the built-in Exception class.
If a class extends the built-in Exception class and
redefines the constructor,
it is highly recommended that it also call Example #1 Extending Exception The above example will output: Caught custom exception CustomException: [5]: Something happened A custom function for this type of exception Throwable hierarchy
The Exception class has many subclasses, among them the SPL exceptions and those defined by extensions. |