aboutsummaryrefslogtreecommitdiff
path: root/tests/run/liftedTry.scala
blob: ff9af98eca3262f12053023bd85374b3eaabce66 (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
object Test {

  def raise(x: Int) = { throw new Exception(s"$x"); 0 }
  def handle: Throwable => Int = { case ex: Exception => ex.getMessage().toInt }

  val x = try raise(1) catch handle

  def foo(x: Int) = {
    val y = try raise(x) catch handle
    y
  }

  foo(try 3 catch handle)

  def main(args: Array[String]) = {
    assert(x == 1)
    assert(foo(2) == 2)
    assert(foo(try raise(3) catch handle) == 3)
    Tr.foo
  }
}

object Tr {
  def fun(a: Int => Unit) = a(2)
  def foo: Int = {
    var s = 1
    s = try {fun(s = _); 3} catch{ case ex: Throwable => val x = 4; s = x; 5 }
    s
  }
}