Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created August 2, 2011 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1120645 to your computer and use it in GitHub Desktop.
Save anonymous/1120645 to your computer and use it in GitHub Desktop.
pmichaud@kiwi:~/nom$ cat z.pir
.include 'except_types.pasm'
.include 'except_severity.pasm'
.sub 'main' :main
$P0 = new ['ExceptionHandler']
set_label $P0, handler1
$P0.'handle_types_except'(.CONTROL_LOOP_NEXT)
push_eh $P0
$P0 = new ['ExceptionHandler']
set_label $P0, handler2
$P0.'handle_types_except'(.CONTROL_ERROR)
push_eh $P0
'a'()
'a'()
.return (0)
handler1:
.local pmc exception
.get_results (exception)
say 'handler1 caught exception'
pop_eh
$P0 = getattribute exception, 'resume'
say 'resuming after exception'
$P0()
handler2:
.get_results (exception)
say 'handler2 caught exception'
pop_eh
$P0 = getattribute exception, 'resume'
say 'resuming after exception'
$P0()
.end
.sub 'a'
say "In subroutine 'a'"
die "first exception"
say "resumed 'a' after first exception"
die .EXCEPT_NORMAL, .CONTROL_LOOP_NEXT
say "resumed 'a' after second exception"
say "leaving 'a'"
.end
pmichaud@kiwi:~/nom$ install/bin/parrot z.pir
In subroutine 'a'
handler1 caught exception
resuming after exception
resumed 'a' after first exception
Warning
No exception handler and no message
current instr.: 'a' pc 101 (z.pir:42)
called from Sub 'main' pc 72 (z.pir:26)
pmichaud@kiwi:~/nom$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment