Bug 6837 - Use Error.pm for error handling
: Use Error.pm for error handling
Status: RESOLVED FIXED
: GridShib
GridShib-CA
: unspecified
: All All
: P3 normal
: ---
Assigned To:
:
:
:
: 6808
  Show dependency treegraph
 
Reported: 2009-08-15 18:13 by
Modified: 2009-11-01 12:52 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2009-08-15 18:13:17
Use Error.pm to clean up error handling.

http://search.cpan.org/dist/Error/
http://www.perl.com/pub/a/2002/11/14/exception.html (not slightly out of date)

For example:
#!/usr/bin/env perl
use Error qw(:try);
use myException;

try {
    test("exceptional world");
}
catch Error with {
    my $ex = shift;
    print "Exception: " . $ex->text() . "\n";
};
#Error::flush();
print "Done.\n";
exit(0);

sub test
{
    my $name = shift;
    print "Hello $name.\n";
    throw myException("Bad code.");
}

---myException.pm--
package myException;

use base qw(Error);
use overload ('""' => 'stringify');

sub new
{
    my $self = shift;
    my $text = "" . shift;
    my @args = ();

    local $Error::Depth = $Error::Depth + 1;
    local $Error::Debug = 1;  # Enables storing of stacktrace

    $self->SUPER::new(-text => $text, @args);
}
1;
------- Comment #1 From 2009-11-01 12:46:18 -------
This is done on HEAD.