2010-08-19 07:01:09 +02:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 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
|
|
|
|
2012-02-01 15:46:40 +01:00
|
|
|
object AkkaException {
|
2012-05-18 19:25:43 +02:00
|
|
|
//FIXME DOC
|
2012-02-05 09:19:57 +01:00
|
|
|
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))
|
2012-02-01 15:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
2012-05-18 19:25:43 +02:00
|
|
|
/**
|
|
|
|
|
* Returns the given Throwables stack trace as a String, or the empty String if no trace is found
|
|
|
|
|
* @param throwable
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
def stackTraceToString(throwable: Throwable): String = throwable.getStackTrace match {
|
|
|
|
|
case null ⇒ ""
|
|
|
|
|
case x if x.length == 0 ⇒ ""
|
|
|
|
|
case trace ⇒
|
|
|
|
|
val sb = new StringBuilder
|
|
|
|
|
for (i ← 0 until trace.length)
|
|
|
|
|
sb.append("\tat %s\n" format trace(i))
|
|
|
|
|
sb.toString
|
2012-02-01 15:46:40 +01:00
|
|
|
}
|
2012-02-07 09:50:03 +01:00
|
|
|
|
2012-02-01 15:46:40 +01: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>
|
|
|
|
|
*/
|
2012-02-07 10:28:42 +01:00
|
|
|
//TODO add @SerialVersionUID(1L) when SI-4804 is fixed
|
2011-04-29 17:15:00 +02:00
|
|
|
class AkkaException(message: String = "", cause: Throwable = null) extends RuntimeException(message, cause) with Serializable {
|
2012-05-18 19:25:43 +02:00
|
|
|
def this(msg: String) = this(msg, null)
|
2011-04-06 15:55:42 +12:00
|
|
|
|
2012-05-18 19:25:43 +02:00
|
|
|
lazy val uuid = java.util.UUID.randomUUID().toString
|
2011-06-17 21:54:02 +02:00
|
|
|
|
2012-05-18 19:25:43 +02:00
|
|
|
override def toString: String = "%s:%s\n[%s]".format(getClass.getName, message, uuid)
|
2011-04-06 15:55:42 +12:00
|
|
|
|
2012-05-18 19:25:43 +02:00
|
|
|
def toLongString: String = "%s:%s\n[%s]\n%s".format(getClass.getName, message, uuid, stackTraceToString)
|
2011-07-25 12:47:43 +03:00
|
|
|
|
2012-05-18 19:25:43 +02:00
|
|
|
def stackTraceToString: String = AkkaException.stackTraceToString(this)
|
2010-08-19 07:01:09 +02:00
|
|
|
}
|
2012-05-16 17:04:13 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This exception is thrown when Akka detects a problem with the provided configuration
|
|
|
|
|
*/
|
|
|
|
|
class ConfigurationException(message: String, cause: Throwable = null) extends AkkaException(message, cause) {
|
|
|
|
|
def this(msg: String) = this(msg, null)
|
|
|
|
|
}
|