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

36 lines
1 KiB
Scala
Raw Normal View History

/**
* Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
*/
package akka
import akka.actor.newUuid
import java.io.{StringWriter, PrintWriter}
import java.net.{InetAddress, UnknownHostException}
/**
* Akka base Exception. Each Exception gets:
* <ul>
* <li>a UUID for tracking purposes</li>
* <li>a message including exception name, uuid, original message and the stacktrace</li>
* <li>a method 'log' that will log the exception once and only once</li>
* </ul>
2010-08-21 16:13:16 +02:00
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
2011-03-26 20:02:33 +01:00
@serializable abstract class AkkaException(message: String = "") extends {
val exceptionName = getClass.getName
val uuid = "%s_%s".format(AkkaException.hostname, newUuid)
} with RuntimeException(message) {
2011-04-05 19:07:27 +12:00
override lazy val toString = "%s\n\t[%s]\n\t%s".format(exceptionName, uuid, message)
}
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"
}
}