Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: rescued, not caught.) |
(Add Seed7 example) |
||
Line 2,023: | Line 2,023: | ||
} |
} |
||
</lang>Exception U0 is caught, exception U1 is caught and re-thrown. Program execution is terminated as the U1 exception is not caught when thrown the second time. |
</lang>Exception U0 is caught, exception U1 is caught and re-thrown. Program execution is terminated as the U1 exception is not caught when thrown the second time. |
||
=={{header|Seed7}}== |
|||
When an [http://seed7.sourceforge.net/manual/errors.htm#Exceptions exception] is not [http://seed7.sourceforge.net/manual/errors.htm#Handlers handled] |
|||
the program is terminated and a [http://seed7.sourceforge.net/manual/errors.htm#Stack_trace stack trace] is written. |
|||
<lang seed7>$ include "seed7_05.s7i"; |
|||
const EXCEPTION: U0 is enumlit; |
|||
const EXCEPTION: U1 is enumlit; |
|||
const proc: baz (in integer: num) is func |
|||
begin |
|||
if num = 1 then |
|||
raise U0; |
|||
else |
|||
raise U1; |
|||
end if; |
|||
end func; |
|||
const proc: bar (in integer: num) is func |
|||
begin |
|||
baz(num); |
|||
end func; |
|||
const proc: foo is func |
|||
local |
|||
var integer: num is 0; |
|||
begin |
|||
for num range 1 to 2 do |
|||
block |
|||
bar(num); |
|||
exception |
|||
catch U0: writeln("U0 catched"); |
|||
end block; |
|||
end for; |
|||
end func; |
|||
const proc: main is func |
|||
begin |
|||
foo; |
|||
end func;</lang> |
|||
{{out}} |
|||
<pre> |
|||
U0 catched |
|||
*** Uncaught EXCEPTION U1 raised with |
|||
{raise U1 } |
|||
Stack: |
|||
in raise (ref EXCEPTION: anException) at /media/disk2_460GiB/home/tm/seed7_5/prg/seed7_05.s7i(322) |
|||
in baz (val integer: num) at rosetta/catchAnExceptionThrownInANestedCall.sd7(11) |
|||
in bar (val integer: num) at rosetta/catchAnExceptionThrownInANestedCall.sd7(17) |
|||
in foo at rosetta/catchAnExceptionThrownInANestedCall.sd7(26) |
|||
in main at rosetta/catchAnExceptionThrownInANestedCall.sd7(35) |
|||
</pre> |
|||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |