catch
clause is unreachable SC-W1072All exceptions such as IllegalArgumentException
are sub types of RuntimeException
. Simply catching Exception
traps all the exceptions. This is a generalized way of trapping all the exceptions and is considered a bad practice. However, if such a case precedes other specific exceptions, they become unreachable. It is therefore recommended that you move generalized exception trapping to the last, or, if possible, drop it entirely.
try {
//
} catch {
case _: Exception =>
case _: IllegalArgumentException => // Unreachable
}
try {
//
} catch {
case _: IllegalArgumentException =>
}