Exceptions Flashcards
How many corresponding catch or finally blocks can a try block have?
It must have at least one.
What are the limitations on objects thrown via a try/catch block?
The thrown object must be an instance of the Exception class or a subclass of Exception. Otherwise, a fatal error will result.
What happens when an exception is thrown but not caught?
A php fatal error will be issued with an “Uncaught Exception…” message, unless a handler has been defined with set_exception_handler().
What is a ‘finally’ block?
In php 5.5 and later, a finally block may be specified after or instead of catch blocks. Code within the finally block will always be executed after the try and catch blocks, regardless of whether an exception has been thrown, and before normal execution resumes.
Do functions use exceptions?
No, they use Error Reporting. However, errors can be simply translated to exceptions with ErrorException.
Can Exceptions be cloned?
No. Attempting to clone an Exception would result in a fatal E_ERROR error.
If a class extends the built-in Exception class and redefines the construction, it is highly recommend to…
…also call parent::__construct() to ensure all available data has been properly assigned.