From ef2de304b1cafdf7bc4f0230f73ed084455fa450 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Fri, 19 May 2006 14:55:15 +0000 Subject: Fixed two try-finally bugs. --- test/files/run/exceptions-2.check | 14 ++++++++++---- test/files/run/exceptions-2.scala | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 5 deletions(-) (limited to 'test/files/run') diff --git a/test/files/run/exceptions-2.check b/test/files/run/exceptions-2.check index 3ec0dfcc1c..e67f147506 100644 --- a/test/files/run/exceptions-2.check +++ b/test/files/run/exceptions-2.check @@ -17,11 +17,17 @@ method3: Exception occurred with stack trace: java.lang.NullPointerException at Test$.method3(exceptions-2.scala:108) - at Test$$anonfun$5.apply(exceptions-2.scala:151) - at Test$$anonfun$5.apply(exceptions-2.scala:151) - at Test$.execute(exceptions-2.scala:128) - at Test$.main(exceptions-2.scala:151) + at Test$$anonfun$5.apply(exceptions-2.scala:180) + at Test$$anonfun$5.apply(exceptions-2.scala:180) + at Test$.execute(exceptions-2.scala:157) + at Test$.main(exceptions-2.scala:180) at Test.main(exceptions-2.scala) +tryFinallyTry: +Silently ignore exception in finally +valInFinally: +Abc +tryAndValInFinally +Abc ================= NoExcep.method2: Hello, world diff --git a/test/files/run/exceptions-2.scala b/test/files/run/exceptions-2.scala index 2583542747..e006bc053d 100644 --- a/test/files/run/exceptions-2.scala +++ b/test/files/run/exceptions-2.scala @@ -1,7 +1,7 @@ /* * Try exception handling and finally blocks. * - * $Id: $ + * $Id$ */ @@ -124,6 +124,35 @@ object Test { Console.println(x); } + def tryFinallyTry: Unit = { + try { + () + } finally { + try { + error("a"); + } catch { + case _ => Console.println("Silently ignore exception in finally"); + } + } + } + + def valInFinally: Unit = + try { + } finally { + val fin = "Abc"; + Console.println(fin); + }; + + def tryAndValInFinally: Unit = + try { + } finally { + val fin = "Abc"; + try { + Console.println(fin); + } catch { case _ => () } + }; + + def execute(f: => Unit) = try { f; } catch { @@ -150,6 +179,14 @@ object Test { Console.println("method3:"); execute(method3); + Console.println("tryFinallyTry:"); + execute(tryFinallyTry); + + Console.println("valInFinally:"); + execute(valInFinally); + Console.println("tryAndValInFinally"); + execute(tryAndValInFinally); + Console.println("================="); Console.println("NoExcep.method2:"); -- cgit v1.2.3