akka.AkkaException.scala Maven / Gradle / Ivy
/**
* Copyright (C) 2009-2012 Typesafe Inc.
*/
package akka
import akka.actor.newUuid
object AkkaException {
def toStringWithStackTrace(throwable: Throwable): String = throwable match {
case null ⇒ "Unknown Throwable: was 'null'"
case ae: AkkaException ⇒ ae.toLongString
case e ⇒ "%s:%s\n%s" format (e.getClass.getName, e.getMessage, stackTraceToString(e))
}
def stackTraceToString(throwable: Throwable): String = {
val trace = throwable.getStackTrace
val sb = new StringBuilder
for (i ← 0 until trace.length)
sb.append("\tat %s\n" format trace(i))
sb.toString
}
}
/**
* Akka base Exception. Each Exception gets:
*
* - a uuid for tracking purposes
* - toString that includes exception name, message and uuid
* - toLongString which also includes the stack trace
*
*/
//TODO add @SerialVersionUID(1L) when SI-4804 is fixed
class AkkaException(message: String = "", cause: Throwable = null) extends RuntimeException(message, cause) with Serializable {
lazy val uuid = newUuid.toString
override lazy val toString =
"%s:%s\n[%s]".format(getClass.getName, message, uuid)
lazy val toLongString =
"%s:%s\n[%s]\n%s".format(getClass.getName, message, uuid, stackTraceToString)
def this(msg: String) = this(msg, null);
def stackTraceToString = AkkaException.stackTraceToString(this)
}