summaryrefslogtreecommitdiff
path: root/test/disabled/presentation/akka/src/akka/AkkaException.scala
blob: 155a7a16b53ecd34dcef998cda9280c9ddbeb9e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * 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>
 *
 * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
 */
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]\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
  }
}

object AkkaException {
  val hostname = try {
    InetAddress.getLocalHost.getHostName
  } catch {
    case e: UnknownHostException => "unknown"
  }
}