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 => System.out.println("Function foo caught exception U0") }
} catch { case e: U0 => println("Function foo caught exception U0") }
}
}


def bar(i: Int) {
def bar(i: Int) {
def baz(i: Int) = { if (i == 0) throw new U0 else throw new U1 }

baz(i) // Nest those calls
baz(i) // Nest those calls
}
}


foo
def baz(i: Int) = { if (i == 0) throw new U0 else throw new U1 }
}

</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.
foo()
}</lang>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==