diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-16 18:29:42 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-16 18:29:42 +0000 |
commit | df50e05006b43b007c2587549030d24b5c154398 (patch) | |
tree | 9edfb1fb5b8c04350a00c163cfcdb1fccd79e3aa /test/files/run/try.scala | |
parent | 17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3 (diff) | |
download | scala-df50e05006b43b007c2587549030d24b5c154398.tar.gz scala-df50e05006b43b007c2587549030d24b5c154398.tar.bz2 scala-df50e05006b43b007c2587549030d24b5c154398.zip |
'test-nsc' has been moved to 'test'.
Diffstat (limited to 'test/files/run/try.scala')
-rw-r--r-- | test/files/run/try.scala | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/test/files/run/try.scala b/test/files/run/try.scala new file mode 100644 index 0000000000..fca6bf5c55 --- /dev/null +++ b/test/files/run/try.scala @@ -0,0 +1,110 @@ +object Test extends AnyRef with Application { + val x = 1; + + def try1 = { + Console.print("1 + 1 = "); + Console.println(1 + ( + try { + x; + } catch { + case _: Error => 1; + } + )); + } + + def try2 = { + Console.print("1 + 1 = "); + Console.println( + (try { x } catch { + case _: Error => 1; + }) + + + (try { x } catch { + case _: Error => 1; + }) + ); + } + + var n = 0; + + def try3 = { + Console.print("1 + 1 = "); + val x = try { 1 } catch { + case e: Error => 1; + } + this.n = try { 1 } catch { + case e: Error => 1; + } + Console.println(x + n); + } + + var instance: AnyRef = null; + + def try4 = { + if (instance == null) { + instance = try { + new String(); + } catch { + case _ => + val cs = "aaa"; + if (cs.length() > 0) { + new String(); + } else { + throw new Error("fatal error"); + null + } + } + } + } + + def try5 = try { + Console.print("1 + 1 = "); + try { + if (true) + error("exit"); + 1+1; + () + } catch { + case _ => + Console.println("2"); + error("for good"); + } + Console.println("a"); + } catch { + case _ => (); + } + + class A { + private val result = { + val y = try { x } catch { + case _: Error => 1; + }; + x + y + } + Console.print("1 + 1 = "); + Console.println(result); + } + +/* + def finally1 = { + Console.print("1 + 1 = "); + Console.println(1 + ( + try { + x + } finally { + () + } + )); + } + +*/ + + try1; + try2; + try3; + try4; + try5; + Console.println; + new A(); + () +} |