Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
imported>Arakov |
|||
Line 218: | Line 218: | ||
'''par''' clause, then all parallel the threads are terminated and the |
'''par''' clause, then all parallel the threads are terminated and the |
||
program continues in the parent thread. <!-- example needed --> |
program continues in the parent thread. <!-- example needed --> |
||
=={{header|Amazing Hopper}}== |
|||
<p>Hopper has a basic "try/catch" handling, and must be handled manually. Only one exception will be lifted.</p> |
|||
<p>VERSION 1: </p> |
|||
<syntaxhighlight lang="bennuGD"> |
|||
#include <jambo.h> |
|||
Main |
|||
e=0, se="" |
|||
Try |
|||
Gosub 'Foo' |
|||
Catch (e) |
|||
Get msg exception, and Move to 'se' |
|||
Printnl ("+-MAIN-FOO CALL Error: ",e, " : ", se ) |
|||
Finish |
|||
End |
|||
Subrutines |
|||
/* |
|||
This "Try" is not considered nested |
|||
*/ |
|||
Define ' Foo ' |
|||
Gosub ' Bar ' |
|||
Return |
|||
Define ' Bar ' |
|||
Set '0', Gosub ' Biz ' |
|||
Set '1', Gosub ' Biz ' |
|||
Return |
|||
Define ' Biz, x ' |
|||
a=0, b=0 |
|||
If ( x ) |
|||
Let ' b:=Sqrt(-1) ' |
|||
Nan( a ) do{ Raise (1000,"\n+----Func BIZ: NaN!") } |
|||
Else |
|||
#( a=log(-1) + log(-1) ) |
|||
Nan( a ) do{ Raise (1001,"\n+----Func BIZ: NaN!") } |
|||
End If |
|||
Printnl ' "a = ", a, " b = ", b ' |
|||
Return |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
+-MAIN FUNC FOO Error: 1001 : |
|||
+----Func BIZ: NaN! |
|||
</pre> |
|||
<p>VERSION 2: </p> |
|||
<syntaxhighlight lang="bennuGD"> |
|||
#include <jambo.h> |
|||
Main |
|||
e=0, se="" |
|||
Try |
|||
Gosub 'Foo' |
|||
Catch (e) |
|||
Get msg exception, and Move to 'se' |
|||
Printnl ("+-MAIN Error: ",e, " : ", se ) |
|||
Finish |
|||
End |
|||
Subrutines |
|||
/* |
|||
This "Try" is not considered nested, then, it is necessary |
|||
to capture the error and raise the error |
|||
*/ |
|||
Define ' Foo ' |
|||
Try |
|||
Gosub ' Bar ' |
|||
Catch (e) |
|||
Get msg exception, and Move to 'se' |
|||
Free try // absolutly nessesary in this chase! |
|||
Raise (e, Cat ("\n+--FUNC FOO: ", se) ) |
|||
Finish |
|||
Return |
|||
Define ' Bar ' |
|||
Try |
|||
Set '0', Gosub ' Biz ' |
|||
Set '1', Gosub ' Biz ' |
|||
Catch(e) |
|||
Get msg exception, and Move to 'se' |
|||
Free try // absolutly nessesary in this chase! |
|||
Raise (e, Cat ("\n+---FUNC BAR: ", se) ) |
|||
Finish |
|||
Return |
|||
Define ' Biz, x ' |
|||
a=0, b=0 |
|||
If ( x ) |
|||
Let ' b:=Sqrt(-1) ' |
|||
Nan( a ) do{ Raise (1000,"\n+----Func BIZ: NaN!") } |
|||
Else |
|||
#( a=log(-1) + log(-1) ) |
|||
Nan( a ) do{ Raise (1001,"\n+----Func BIZ: NaN!") } |
|||
End If |
|||
Printnl ' "a = ", a, " b = ", b ' |
|||
Return |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
+-MAIN Error: 1001 : |
|||
+--FUNC FOO: |
|||
+---FUNC BAR: |
|||
+----Func BIZ: NaN! |
|||
</pre> |
|||
=={{header|APL}}== |
=={{header|APL}}== |