Non-fatal exceptions

| No Comments | No TrackBacks

Parrot's exceptions have a 'severity' attribute to indicate, of course, how severe the exception is. The current severities are: (taken from runtime/parrot/include/except_severity.pasm

EXCEPT_NORMAL   
EXCEPT_WARNING  
EXCEPT_ERROR    
EXCEPT_SEVERE   
EXCEPT_FATAL    
EXCEPT_DOOMED   
EXCEPT_EXIT

For a long time now, the spec has said that non-fatal exceptions shouldn't cause termination of the program, but should result in the message being printed and normal execution resuming. This hasn't been the case until today. It was a pretty simple change, but should make some things much nicer in the future.

Here's a simple program demonstrating this behaviour:

.include 'include/except_severity.pasm'
.sub main :main
    say 'before the warning'
    $P0 = new 'Exception'
    $P0['severity'] = .EXCEPT_WARNING
    $P0['message'] = "\tOMG something is kinda wrong"
    throw $P0
    say 'after the warning'
.end

And here's the output:

[sweeks@kweh parrot]$ ./parrot et.pir
before the warning
    OMG something is kinda wrong
after the warning

I've also updated Perl 6's warn() to use a non-fatal exception, meaning that these can now be caught.

No TrackBacks

TrackBack URL: http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/104

Leave a comment

About this Entry

This page contains a single entry by Stephen Weeks published on December 15, 2008 7:03 AM.

Currying in Perl 6 was the previous entry in this blog.

Perl 6 - Given/When is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.25