[% setvar title messages.rfc - An RFC to discussing the wisdom of allowing run time errorand warning messages to be modified at run time %]

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

messages.rfc - An RFC to discussing the wisdom of allowing run time error and warning messages to be modified at run time

VERSION

  Maintainer: Corwin Brust <cbrust@alldata.net>
  Date: 1 Aug 2000
  Mailing List: perl6-language@perl.org
  Number: 3
  Version: 1
  Status: Developing

ABSTRACT

I'm probably wrong in this, but I rather think this one's explains it self.

I want perl's error (and warning) messages to be specific to each program I write.

DESCRIPTION

I have, and I cannot assume I am alone in this, spent a fair amount of time creating subroutines which trap various error responses from Perl, only to turn right around and 'die' with an error message of my own, differing only in the text shown when the program terminates.

Wouldn't it be great if we could just reword the existing error messages on a per-script basis to be relevant to that program, and let Perl's normal error handling mechanism do the work of presenting the user with the bad news.

IMPLEMENTATION

It seems, as of this writing, that the means for accessing Perl internal variables will not be as it has been. Any method of allowing for program writer defined messages would have to be closely time to whatever new mechanism we find agreeable. But...

  $perl::core::err{TYPE_MISMATCH} = {
                                     fatal => 1,
                                     handler => sub { 
                                                      my $arg = shift; 
                                                      my $func = shift;
                                                      my $correct_type = shift;
                                                      my $sent_type = shift;
                                                      my $prog = shift;
                                                      my $line = shift;
                                                      my $near = shift;
                                                      CORE::die(qq[Type of
$arg to $func must be $correct_type (not $sent_type) at $prog line $line,
$near\n]);
                                                     },
                                    }
Where CORE::die is able to look for a true value in
$perl::core::err{TYPE_MISMATCH}->{fatal} and either die or issue a warning
as appropriate.

And, yeah, I'm sure there's a better way to implement this. I hope, however, that I have shown such a thing can be done.

REFERENCES