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

44 lines
1.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.net.{InetAddress, UnknownHostException}
/**
* Akka base Exception. Each Exception gets:
* <ul>
* <li>a uuid for tracking purposes</li>
* <li>toString that includes exception name, message, uuid, and the stacktrace</li>
* </ul>
2010-08-21 16:13:16 +02:00
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
class AkkaException(message: String = "") extends RuntimeException(message) with Serializable {
val uuid = "%s_%s".format(AkkaException.hostname, newUuid)
override lazy val toString = {
val name = getClass.getName
val trace = stackTraceToString
"%s: %s\n[%s]\n%s".format(name, message, uuid, trace)
}
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"
}
}