I have the following dummy Scala code in the file test.scala
:
class Transaction {
def begin() {}
def commit() {}
def rollback() {}
}
object Test extends Application {
def doSomething() {}
val t = new Transaction()
t.begin()
try {
doSomething()
t.commit()
} catch {
case _ => t.rollback()
}
}
If I compile this on Scala 2.8 RC1 with scalac -Xstrict-warnings test.scala
I'll get the following warning:
test.scala:16: warning: catch clause swallows everything: not advised.
case _ => t.rollback()
^
one warning found
So, if catch-all expressions are not advised, how am I supposed to implement such a pattern instead? And apart from that why are such expressions not advised anyhow?