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 08:52, 9 June 2015
, 9 years agoadded swift
m (→{{header|Sidef}}: minor fix) |
(added swift) |
||
Line 2,333:
CatchMeIfYouCan new foo</lang>
=={{header|Swift}}==
{{works with|Swift|2.x+}}
<lang swift>enum MyException : ErrorType {
case U0
case U1
}
func foo() throws {
for i in 0 ... 1 {
do {
try bar(i)
} catch MyException.U0 {
print("Function foo caught exception U0")
}
}
}
func bar(i: Int) throws {
try baz(i) // Nest those calls
}
func baz(i: Int) throws {
if i == 0 {
throw MyException.U0
} else {
throw MyException.U1
}
}
try foo()</lang>
{{out}}
<pre>
Function foo caught exception U0
error caught in main()
</pre>
=={{header|Tcl}}==
|