I'm wondering about something regarding PHP's try
, catch
statements.
Let's consider the following example.
abstract class ExceptionA extends Exception
{}
class ExceptionB extends ExceptionA
{}
class ExceptionTest
{
public function example()
{
try {
throw new ExceptionB();
} catch ( ExceptionB $e ) {
echo 'ExceptionB was caught';
} catch ( ExceptionA $e ) {
echo 'ExceptionA was caught';
} catch ( Exception $e ) {
echo 'Exception was caught';
}
}
}
All catch
statements match the exception. Where the first (ExceptionB
) is the closest match.
Will the order of the catch
statements be of influence to which one will catch it?