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

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
Line 852: Line 852:
=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang dyalect>type U0()
<lang dyalect>var bazCallCount = 0
type U1()
var bazCallCount = 0

func baz() {
func baz() {
bazCallCount += 1
bazCallCount += 1
if bazCallCount == 1 {
if bazCallCount == 1 {
throw U0()
throw "Err0"
} else if bazCallCount == 2 {
} else if bazCallCount == 2 {
throw U1()
throw "Err1"
}
}
}
}

func bar() {
func bar() {
baz()
baz()
}
}

func foo() {
func foo() {
var calls = 2
var calls = 2
Line 875: Line 873:
bar()
bar()
} catch {
} catch {
U0() => print("U0 caught.")
UnexpectedError("Err0") => print("Err0 caught.")
}
}
calls -= 1
calls -= 1
}
}
}
}</lang>

foo()</lang>


{{out}}
{{out}}


<pre>U0 caught.
<pre>Err0 caught.
Runtime exception Dy601: U1
Runtime exception Dy601: Err1
Stack trace: ...</pre>
Stack trace: ...</pre>