Scala

Scala

By DeepSource

Catch clauses should do more than just rethrow exceptions SC-R1057

Anti-pattern

Catch clauses that simply catch and rethrow exceptions are redundant and can be removed. Exceptions are usually thrown in situations when something goes wrong. The severity of these situations may vary depending on what your application is attempting to do. The catch clause allows you to trap one or more exceptions and provides you a way to recover gracefully from these situations. Simply trapping an exception and immediately throwing it without logging or attempting any recovery does not make any sense. It is either recommended that you do more than simply rethrowing exceptions or remove the exception handling altogether.

Bad Practice

try {
  str.toInt
} catch {
  case ex: NumberFormatException => println("Oops")
}

Recommended

try {
  str.toInt
} catch {
  case ex: NumberFormatException => ex.printStackTrace()
}

References