Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(→{{header|Scala}}: Marked incomplete. Needs to "Show/describe what happens when the program is run.") |
|||
Line 1,980: | Line 1,980: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{incorrect|Scala|Show/describe what happens when the program is run.}} |
|||
[[Category:Scala Implementations]]{{libheader|Scala}}<lang Scala>object ExceptionsTest extends App { |
[[Category:Scala Implementations]]{{libheader|Scala}}<lang Scala>object ExceptionsTest extends App { |
||
class U0 extends Exception |
class U0 extends Exception |
||
class U1 extends Exception |
class U1 extends Exception |
||
def foo |
def foo { |
||
for (i <- 0 to 1) |
for (i <- 0 to 1) |
||
try { |
try { |
||
bar(i) |
bar(i) |
||
} catch { case e: U0 => |
} catch { case e: U0 => println("Function foo caught exception U0") } |
||
} |
} |
||
def bar(i: Int) { |
def bar(i: Int) { |
||
⚫ | |||
baz(i) // Nest those calls |
baz(i) // Nest those calls |
||
} |
} |
||
⚫ | |||
⚫ | |||
} |
|||
</lang>Exception U0 is caught, exception U1 is caught and re-thrown. Program execution is terminated as the U1 exception is not caught when thrown the second time. |
|||
⚫ | |||
}</lang> |
|||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |