Skip to content

MIR1508

UnreachableCatch

A catch block is unreachable because a more general exception type is caught before a more specific one. Exception types should be ordered from most specific to most general.

<?php
try {
// Some code
} catch (Exception $e) {
// General catch
} catch (InvalidArgumentException $e) {
// This is unreachable - Exception already caught
}

Order catch blocks from most specific to most general:

<?php
try {
// Some code
} catch (InvalidArgumentException $e) {
// Specific catch first
} catch (Exception $e) {
// General catch last
}