For example, Exception
is the base class for all user-defined exceptions, so when you catch it, the later exception handling will no be reached. This checks for Exception
and Throwable
.
<?php
class ApplicationError extends Exception {}
try {
something();
} catch (Exception $e) {
echo "general error";
} catch (ApplicationError $e) { // UnreachableCatch: This exception handling will not be reached.
echo "application error";
}
<?php
class ApplicationError extends Exception {}
try {
something();
} catch (ApplicationError $e) { // OK!
echo "application error";
} catch (Exception $e) {
echo "general error";
}