File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 111
22failed
33failed
4+ 2
Original file line number Diff line number Diff line change @@ -12,17 +12,22 @@ object scalax:
1212 private class Result [T ]:
1313 var value : T = scala.compiletime.uninitialized
1414
15- def try1 [R , E <: Exception ](body : => R throws E ): (E => Unit ) => R = { c =>
15+ def try1 [R , E <: Exception ](body : => R throws E )(c : E => Unit ): R =
16+ try2(body)(c) {}
17+
18+ def try2 [R , E <: Exception ](body : => R throws E )(c : E => Unit )(f : => Unit ): R =
1619 val res = new Result [R ]
1720 try
1821 given CanThrow [E ] = ???
1922 res.value = body
2023 catch c.asInstanceOf [Throwable => Unit ]
24+ finally f
2125 res.value
22- }
2326
2427 extension [R , E <: Exception ](t : (E => Unit ) => R ) def catch1 (c : E => Unit ) = t(c)
2528
29+ extension [R , E <: Exception ](c : ( => Unit ) => R ) def finally1 (f : => Unit ) = c(f)
30+
2631import scalax ._
2732
2833def foo (x : Boolean ): Int throws Fail =
@@ -39,9 +44,11 @@ def baz: Int throws Exception = foo(false)
3944 case ex : Fail =>
4045 println(" failed" )
4146 }
42- try1 {
47+ try2 {
4348 println(baz)
4449 } catch1 {
4550 case ex : Fail =>
4651 println(" failed" )
52+ } finally1 {
53+ println(2 )
4754 }
You can’t perform that action at this time.
0 commit comments