All Downloads are FREE. Search and download functionalities are using the official Maven repository.

akka.util.NonFatal.scala Maven / Gradle / Ivy

There is a newer version: 2.0.5-protobuf-2.5-java-1.5
Show newest version
/**
 * Copyright (C) 2009-2012 Typesafe Inc. 
 */
package akka.util

/**
 * Extractor of non-fatal Throwables. Will not match fatal errors
 * like VirtualMachineError (OutOfMemoryError)
 * ThreadDeath, LinkageError and InterruptedException.
 * StackOverflowError is matched, i.e. considered non-fatal.
 *
 * Usage to catch all harmless throwables:
 * {{{
 *   try {
 *     // dangerous stuff
 *   } catch {
 *     case NonFatal(e) => log.error(e, "Something not that bad")
 *   }
 * }}}
 */
object NonFatal {

  def unapply(t: Throwable): Option[Throwable] = t match {
    case e: StackOverflowError ⇒ Some(e) // StackOverflowError ok even though it is a VirtualMachineError
    // VirtualMachineError includes OutOfMemoryError and other fatal errors
    case _: VirtualMachineError | _: ThreadDeath | _: InterruptedException | _: LinkageError ⇒ None
    case e ⇒ Some(e)
  }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy