Scala: Silently catch all exceptions

后端 未结 8 1561
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 05:34

Empty catch block seems to be invalid in Scala

try {
  func()
} catch {

} // error: illegal start of simple expression

How I can catch all

8条回答
  •  梦毁少年i
    2020-12-31 05:58

    Inside of Scala's catch block you need to use similar construct as in a match statement:

    try {
      func()
    } catch {
      case _: Throwable => // Catching all exceptions and not doing anything with them
    }
    

提交回复
热议问题