Exceptions/Catch an exception thrown in a nested call: Difference between revisions

Scala added
(Added zkl)
(Scala added)
Line 1,979:
<lang ruby>[1, 2].each {|$bazcount| foo}</lang>
 
=={{header|SmalltalkScala}}==
[[Category:Scala Implementations]]{{libheader|Scala}}<lang Scala>object ExceptionsTest extends App {
class U0 extends Exception
 
class U1 extends Exception
{{works with|Smalltalk/X}}
 
functional code, not class based, using blocks as functions, and anonymous exceptions (signals):
def foo() {
for (i <- 0 to 1)
try {
bar(i)
} catch { case e: U0 => System.out.println("Function foo caught exception U0") }
}
 
def bar(i: Int) {
baz(i) // Nest those calls
}
 
def baz(i: Int) = { if (i == 0) throw new U0 else throw new U1 }
 
foo()
}</lang>
 
=={{works withheader|Smalltalk/X}}==
{{works with|Smalltalk/X}}functional code, not class based, using blocks as functions, and anonymous exceptions (signals):
<lang Smalltalk>| u0 u1 foo bar baz|
 
Line 2,012 ⟶ 2,032:
] value.
 
foo value</lang>
</lang>
 
"traditional" implementation, using class based exceptions, and method invocations:
 
<lang Smalltalk>Exception
subclass: #U0
Anonymous user