diff options
author | Philipp Haller <hallerp@gmail.com> | 2009-05-27 23:27:47 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2009-05-27 23:27:47 +0000 |
commit | d94cac09a0f0a82440305e787c62718b3baccf5e (patch) | |
tree | e76227c9161a2c02a30971d87d4355a7a6346143 /test/files | |
parent | 93a27b6d75ad9db73fd8133b3142dd85fc158d5f (diff) | |
download | scala-d94cac09a0f0a82440305e787c62718b3baccf5e.tar.gz scala-d94cac09a0f0a82440305e787c62718b3baccf5e.tar.bz2 scala-d94cac09a0f0a82440305e787c62718b3baccf5e.zip |
Added test for Actor.exceptionHandler.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/jvm/actor-exceptions.check | 11 | ||||
-rw-r--r-- | test/files/jvm/actor-exceptions.scala | 47 |
2 files changed, 58 insertions, 0 deletions
diff --git a/test/files/jvm/actor-exceptions.check b/test/files/jvm/actor-exceptions.check new file mode 100644 index 0000000000..021ccea1f1 --- /dev/null +++ b/test/files/jvm/actor-exceptions.check @@ -0,0 +1,11 @@ +problem +received A +problem +received A +problem +received A +problem +received A +problem +received last A +slave exited because of java.lang.Exception: unhandled diff --git a/test/files/jvm/actor-exceptions.scala b/test/files/jvm/actor-exceptions.scala new file mode 100644 index 0000000000..ccec84c56c --- /dev/null +++ b/test/files/jvm/actor-exceptions.scala @@ -0,0 +1,47 @@ + +import scala.actors.{Actor, Exit} +import Actor._ + +case class MyException(text: String) extends Exception + +object Master extends Actor { + trapExit = true + def act() { + link(Slave) + Slave.start() + for (i <- 0 until 10) Slave ! A + react { + case Exit(from, reason) => println("slave exited because of "+reason) + } + } +} + +object Slave extends Actor { + override def exceptionHandler: PartialFunction[Exception, Unit] = { + case MyException(text) => println(text) + } + def act() { + var cnt = 0 + loop { + react { + case A => + cnt += 1 + if (cnt % 2 != 0) throw MyException("problem") + if (cnt < 10) + println("received A") + else { + println("received last A") + throw new Exception("unhandled") + } + } + } + } +} + +case object A + +object Test { + def main(args: Array[String]) { + Master.start() + } +} |