pekko/akka-actor/src/main/scala/akka/AkkaException.scala

45 lines
1.2 KiB
Scala
Raw Normal View History

/**
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
*/
package akka
import akka.actor.newUuid
import java.net.{ InetAddress, UnknownHostException }
2011-07-15 10:59:29 +03:00
/**
* Akka base Exception. Each Exception gets:
* <ul>
* <li>a uuid for tracking purposes</li>
* <li>toString that includes exception name, message and uuid</li>
* <li>toLongString which also includes the stack trace</li>
* </ul>
2010-08-21 16:13:16 +02:00
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
2011-04-29 17:15:00 +02:00
class AkkaException(message: String = "", cause: Throwable = null) extends RuntimeException(message, cause) with Serializable {
val uuid = "%s_%s".format(AkkaException.hostname, newUuid)
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 stackTraceToString = {
val trace = getStackTrace
val sb = new StringBuffer
for (i 0 until trace.length)
sb.append("\tat %s\n" format trace(i))
sb.toString
}
}
2011-02-28 22:54:32 +01:00
object AkkaException {
2010-08-21 16:13:16 +02:00
val hostname = try {
InetAddress.getLocalHost.getHostName
} catch {
case e: UnknownHostException "unknown"
}
}