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