diff options
author | Philipp Haller <hallerp@gmail.com> | 2010-04-12 11:59:29 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2010-04-12 11:59:29 +0000 |
commit | 800d9d8fe9c62018779d813edf9ab6dde9033d8c (patch) | |
tree | 0dff599939aa4afbd4ce0bd3579b8915dff8d34b /src | |
parent | 81c7ff7ef7243da2689064fe502c4b5e58108b22 (diff) | |
download | scala-800d9d8fe9c62018779d813edf9ab6dde9033d8c.tar.gz scala-800d9d8fe9c62018779d813edf9ab6dde9033d8c.tar.bz2 scala-800d9d8fe9c62018779d813edf9ab6dde9033d8c.zip |
actors.UncaughtException stores most recent sen...
actors.UncaughtException stores most recent sender. Default output for
unhandled exceptions can be disabled using actors.Debug. Review by
plocinic.
Diffstat (limited to 'src')
-rw-r--r-- | src/actors/scala/actors/ActorTask.scala | 11 | ||||
-rw-r--r-- | src/actors/scala/actors/Debug.scala | 31 | ||||
-rw-r--r-- | src/actors/scala/actors/ReactorTask.scala | 9 | ||||
-rw-r--r-- | src/actors/scala/actors/UncaughtException.scala | 3 |
4 files changed, 29 insertions, 25 deletions
diff --git a/src/actors/scala/actors/ActorTask.scala b/src/actors/scala/actors/ActorTask.scala index bceea06072..2fa24f93af 100644 --- a/src/actors/scala/actors/ActorTask.scala +++ b/src/actors/scala/actors/ActorTask.scala @@ -30,9 +30,18 @@ private[actors] class ActorTask(actor: Actor, } protected override def terminateExecution(e: Exception) { + val senderInfo = try { Some(actor.sender) } catch { + case _: Exception => None + } + val uncaught = new UncaughtException(actor, + if (msg != null) Some(msg) else None, + senderInfo, + currentThread, + e) + actor.synchronized { if (!actor.links.isEmpty) - actor.exitLinked(e) + actor exitLinked uncaught } } diff --git a/src/actors/scala/actors/Debug.scala b/src/actors/scala/actors/Debug.scala index bad19b8aeb..f28156fc9a 100644 --- a/src/actors/scala/actors/Debug.scala +++ b/src/actors/scala/actors/Debug.scala @@ -11,22 +11,28 @@ package scala.actors /** + * Provides methods for generating debugging output. + * * @author Philipp Haller */ -object Debug { +object Debug extends Logger("") {} + +private[actors] class Logger(tag: String) { private var lev = 2 def level = lev def level_= (lev: Int) = { this.lev = lev } + private val tagString = if (tag == "") "" else " ["+tag+"]" + def info(s: String) = - if (lev > 2) System.out.println("Info: " + s) + if (lev > 2) System.out.println("Info" + tagString + ": " + s) def warning(s: String) = - if (lev > 1) System.err.println("Warning: " + s) + if (lev > 1) System.err.println("Warning" + tagString + ": " + s) def error(s: String) = - if (lev > 0) System.err.println("Error: " + s) + if (lev > 0) System.err.println("Error" + tagString + ": " + s) def doInfo(b: => Unit) = if (lev > 2) b @@ -38,18 +44,5 @@ object Debug { if (lev > 0) b } -class Debug(tag: String) { - private var lev = 2 - - def level = lev - def level_= (lev: Int) = { this.lev = lev } - - def info(s: String) = - if (lev > 2) System.out.println(tag + " (info): " + s) - - def warning(s: String) = - if (lev > 1) System.err.println(tag + " (warn): " + s) - - def error(s: String) = - if (lev > 0) System.err.println(tag + " (erro): " + s) -} +@deprecated("this class is going to be removed in a future release") +class Debug(tag: String) extends Logger(tag) {} diff --git a/src/actors/scala/actors/ReactorTask.scala b/src/actors/scala/actors/ReactorTask.scala index ac809f04ff..3f9ebb6fa7 100644 --- a/src/actors/scala/actors/ReactorTask.scala +++ b/src/actors/scala/actors/ReactorTask.scala @@ -53,12 +53,13 @@ private[actors] class ReactorTask[Msg >: Null](var reactor: Reactor[Msg], // print message on default error stream val msgException = "Uncaught exception in "+reactor+"\n" val msgMessage = if (msg != null) "Message: "+msg+"\n" else "" - Console.err.print(msgException + msgMessage) - e.printStackTrace() + Debug.doWarning { + Console.err.print(msgException + msgMessage) + e.printStackTrace() + } - val uncaught = new UncaughtException(reactor, if (msg != null) Some(msg) else None, currentThread, e) + terminateExecution(e) reactor.terminated() - terminateExecution(uncaught) } finally { suspendExecution() this.reactor = null diff --git a/src/actors/scala/actors/UncaughtException.scala b/src/actors/scala/actors/UncaughtException.scala index 30043465a1..54c28f66cf 100644 --- a/src/actors/scala/actors/UncaughtException.scala +++ b/src/actors/scala/actors/UncaughtException.scala @@ -21,11 +21,12 @@ package scala.actors */ class UncaughtException[Msg >: Null](val actor: Reactor[Msg], val message: Option[Msg], + val sender: Option[OutputChannel[Any]], val thread: Thread, cause: Exception) extends Exception(cause) { override def toString() = - "UncaughtException("+actor+","+message+","+cause+")" + "UncaughtException("+actor+","+message+","+sender+","+cause+")" } |