File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -20,26 +20,28 @@ def baz: Int throws Exception = foo(false)
20
20
class Result [T ]:
21
21
var value : T = scala.compiletime.uninitialized
22
22
23
- def tryCatch [R , E <: Exception ](body : => R throws E )( c : E => Unit , f : => Unit = ()) : R =
23
+ def try1 [R , E <: Exception ](body : => R throws E ): ( E => Unit ) => R = { c =>
24
24
val res = new Result [R ]
25
25
try
26
26
given CanThrow [E ] = ???
27
27
res.value = body
28
28
catch c.asInstanceOf [Throwable => Unit ]
29
- finally f
30
29
res.value
30
+ }
31
+
32
+ extension [R , E <: Exception ](t : (E => Unit ) => R ) def catch1 (c : E => Unit ) = t(c)
31
33
32
34
@ main def Test =
33
- tryCatch ({
35
+ try1 ({
34
36
println(foo(true ))
35
37
println(foo(false ))
36
- })({
38
+ }).catch1 ({
37
39
case ex : Fail =>
38
40
println(" failed" )
39
41
})
40
- tryCatch (
42
+ try1 (
41
43
println(baz)
42
- )({
44
+ ).catch1 ({
43
45
case ex : Fail =>
44
46
println(" failed" )
45
47
})
You can’t perform that action at this time.
0 commit comments