[% setvar title A Base Class for Exception Objects %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/

TITLE

A Base Class for Exception Objects

VERSION

  Maintainer: Tony Olekshy <olekshy@avrasoft.com>
  Date: 12 Aug 2000
  Last Modified: 1 Oct 2000
  Mailing List: perl6-language-errors@perl.org
  Number: 96
  Version: 2
  Status: Withdrawn

ABSTRACT

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

DESCRIPTION

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

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.

Instance Variables

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

    tag

	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?

    severity

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

	What should the default be if not otherwise specified?

    message

	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.

    debug

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

    file

	The file from which the constructor was called.

    line

	The line from which the constructor was called.

    object

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

    sysmsg

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

Methods

    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}   }

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 { ... }

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?

REFERENCES

RFC 70: Allow exception-based error-reporting.

RFC 80: Exception objects and classes for builtins.

RFC 63: Exception handling syntax proposal (Error.pm)

RFC 88: Structured Exception Handling Mechanism (Try.pm)