Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try/Catch: Object Exception is not a value

Tags:

scala

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?

like image 934
Andrew Avatar asked Sep 18 '26 18:09

Andrew


1 Answers

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.

like image 80
Régis Jean-Gilles Avatar answered Sep 21 '26 11:09

Régis Jean-Gilles