Scala

Scala

Made by DeepSource

Exception in catch clause is unreachable SC-W1072

Bug risk
Critical

All 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.

Bad Practice

try {
  //
} catch {
  case _: Exception =>
  case _: IllegalArgumentException => // Unreachable
}

Recommended

try {
  //
} catch {
  case _: IllegalArgumentException =>
}