develooper Front page | perl.perl6.announce.rfc | Postings from October 2000

RFC 96 (v2) A Base Class for Exception Objects

Perl6 RFC Librarian
October 1, 2000 17:33
RFC 96 (v2) A Base Class for Exception Objects
Message ID:
This and other RFCs are available on the web at

=head1 TITLE

A Base Class for Exception Objects

=head1 VERSION

  Maintainer: Tony Olekshy <>
  Date: 12 Aug 2000
  Last Modified: 1 Oct 2000
  Mailing List:
  Number: 96
  Version: 2
  Status: Withdrawn


The contents of this RFC are now covered by RFC 88 and RFC 80.


A number of topics in the Perl 6 RFC discussions have touched on
the concept of a sanctioned or canonical base class for exception

This RFC considers a basic proposal for a base class for exception
objects that can be used with core Perl, traditional eval, die, and
$@ functionality, and with exception handling mechanisms like RFC 63
and RFC 88.

One of the attributes of an exception object is its class name.
This can be changed via inheritance, and a hierarchy of isa
relationships can be arranged.  Exception handing mechanisms can
arrange to have catch behaviour depend on these relationships.

=head2 Instance Variables

The following exception object instance variables are supported by
this base class.


	This is a string which module developers can use to assign
	a unique "identifier" to each exception object constructor
	invocation in the module.

	What should the default be if not otherwise specified?


	This is some sort of "priority" (such as info v/s fatal) on
	which handing can be based.  The details need to be worked

	What should the default be if not otherwise specified?


	This is a description of the exception in language intended
	for the "end user".  This is the only required ivar, so as
	such the constructor treats it specially.


	This is a place for additional description that is not
	intended for the end user (because it is "too technical"
	or "sensitive").


	The file from which the constructor was called.


	The line from which the constructor was called.


	If the exception is related to an object, it can be
	specified here.  Should this be a weak reference?


	This a place for the internal exceptions raised by Perl
	to record system information, along the lines of $!.


    sub new
	my ($C, $msg, %A) = @_;

	exists $A{file}   or $A{file}   = caller ...
	exists $A{line}   or $A{line}   = caller ...
	exists $A{sysmsg} or $A{sysmsg} = magic  ...

	bless {message => $msg, %A}, ref $C || $C;

    sub tag      { @_ > 1 and $_[0]->{tag}      = $_[1]; $_[0]->{tag}      }
    sub severity { @_ > 1 and $_[0]->{severity} = $_[1]; $_[0]->{severity} }
    sub message  { @_ > 1 and $_[0]->{message}  = $_[1]; $_[0]->{message}  }
    sub debug    { @_ > 1 and $_[0]->{debug}    = $_[1]; $_[0]->{debug}    }
    sub file     { @_ > 1 and $_[0]->{file}     = $_[1]; $_[0]->{file}     }
    sub line     { @_ > 1 and $_[0]->{line}     = $_[1]; $_[0]->{line}     }
    sub object   { @_ > 1 and $_[0]->{object}   = $_[1]; $_[0]->{object}   }
    sub sysmsg   { @_ > 1 and $_[0]->{sysmsg}   = $_[1]; $_[0]->{sysmsg}   }

=head1 IMPACT

Once a standard set of attributes is decided on, RFC 88 can be
revised to provide exception tests like:

    except tag => "ABC.1234" => catch { ... }

    except severity => "Fail" => catch { ... }

=head1 ISSUES

How to extend ivars and control namespace?

How to extend methods and control namespace?

Default values for tag and severity?

How to categorize severity?

How to arrange the exception class hierarchy for the Perl core?

How to tag exceptions in the Perl core?

What assertions should be placed on the instance variables?

What should stringification return?


RFC 70: Allow exception-based error-reporting.

RFC 80: Exception objects and classes for builtins.

RFC 63: Exception handling syntax proposal (

RFC 88: Structured Exception Handling Mechanism ( Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About