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:41, 18 January 2017
, 7 years agoAdded Kotlin
(Added FreeBASIC) |
(Added Kotlin) |
||
Line 1,624:
"We caught U0"
jq: error: U1
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
class U0 : Throwable("U0 occurred") {}
class U1 : Throwable("U1 occurred") {}
fun foo() {
for (i in 1..2)
try {
bar(i)
}
catch(e: U0) {
println(e.message)
}
}
fun bar(i: Int) {
baz(i)
}
fun baz(i: Int) {
when (i) {
1 -> throw U0()
2 -> throw U1()
}
}
fun main(args: Array<String>) {
foo()
}</lang>
{{out}}
<pre>
U0 occurred
Exception in thread "main" U1: U1 occurred
at ExceptionsKt.baz(exceptions.kt:23)
at ExceptionsKt.bar(exceptions.kt:17)
at ExceptionsKt.foo(exceptions.kt:9)
at ExceptionsKt.main(exceptions.kt:28)
</pre>
=={{header|Lasso}}==
|