Anonymous user
Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Exceptions/Catch an exception thrown in a nested call (view source)
Revision as of 16:21, 24 June 2014
, 9 years agoScala added
(Added zkl) |
(Scala added) |
||
Line 1,979:
<lang ruby>[1, 2].each {|$bazcount| foo}</lang>
=={{header|
[[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 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
|