Andrew
Andrew

Reputation: 6404

Try/Catch: Object Exception is not a value

I am trying to catch different types of exceptions but I am stuck on an error. I imported scala.util.control.Exception._

try {
        isAuthenticatedJson(f)
    }catch {
      //object RuntimeException is not a value
      case RuntimeException => {}
      //object Exception is not a value
      case Exception => {}
    }  

What am I missing?

Upvotes: 2

Views: 2415

Answers (1)

Régis Jean-Gilles
Régis Jean-Gilles

Reputation: 32739

Try this (note the underscore):

try {
    isAuthenticatedJson(f)
} catch {
  case _: RuntimeException => {}
  case _: Exception => {}
}

This is a "typed pattern". See http://www.scala-lang.org/node/120.

Upvotes: 13

Related Questions