Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/run/rescue.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
object lib {
inline def (op: => T) rescue[T] (fallback: => T) = try op catch { case _: Throwable => fallback }
inline def (op: => T) rescue[T, E <: Throwable] (fallback: E => T) = try op catch { case ex: E => fallback(ex) }
}

import lib._

@main def Test = {
assert((9 / 1 rescue 1) == 9)
assert((9 / 0 rescue 1) == 1)
assert(((9 / 0 rescue { ex: NullPointerException => 5 }) rescue 10) == 10)
assert(((9 / 0 rescue { ex: ArithmeticException => 5 }) rescue 10) == 5)

assert((9 / 0 rescue {
case ex: NullPointerException => 4
case ex: ArithmeticException => 3
}) == 3)
}