Error::throw():Bionanny::Base::throw():
Bionanny::Exception - Generic exception object for Bionanny
Error::throw():
use Bionanny::Exception;
use Error;
# Set Error::Debug to include stack trace data in the error messages
$Error::Debug = 1;
$file = shift;
open (IN, $file) ||
throw Bionanny::Exception ( "Can't open file $file for reading", $!);
Bionanny::Base::throw():
# Here we have an object that ISA Bionanny::Base, so it inherits throw().
open (IN, $file) ||
$object->throw(-class => 'Bionanny::Exception',
-text => "Can't open file $file for reading",
-value => $!);
use Bionanny::Exception;
# Note that we need to import the 'try' tag from Error.pm
use Error qw(:try);
# Set Error::Debug to include stack trace data in the error messages
$Error::Debug = 1;
$file = shift;
try {
open (IN, $file) ||
throw Bionanny::Exception ( "Can't open file $file for reading", $!);
}
catch Bionanny::Exception with {
my $err = shift;
print STDERR "Using default input file: $default_file\n";
open (IN, $default_file) || die "Can't open $default_file";
}
otherwise {
my $err = shift;
print STDERR "An unexpected exception occurred: \n$err";
# By placing an the error object reference within double quotes,
# you're invoking its stringify() method.
}
finally {
# Any code that you want to execute regardless of whether or not
# an exception occurred.
};
# the ending semicolon is essential!
@Bionanny::TestException::ISA = qw( Bionanny::Exception );
The Bionanny::Exception is an extension of Graham Barr's Error.pm module available from CPAN.
Martin Senger (support@bionanny.org)
This file is a component of the Bionanny project. Copyright Michael Niemi & Martin Senger. For details contact support@bionanny.org, or see http://www.bionanny.org/.
Parts were re-factored from modules available in Bioperl project. See copyright notices there.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This software is provided ``as is'' without warranty of any kind.
The arguments, in the key-value style, are the same as for Error::new().
You can also specify plain arguments as ($message, $value) where $value is optional.
-value, if defined, must be non-zero and not an empty string in
order for eval{}-based exception handlers to work. These require that
if($@) evaluates to true, which will not be the case if the Error has
no value (Error overloads numeric operations to the Error::value()
method).
It is OK to create Bionanny::Exception objects without specifing
-value. In this case, an invisible dummy value is used.
If you happen to specify a -value of zero (0), it will
be replaced by the string ``The number zero (0)''.
If you happen to specify a -value of empty string (``''), it will
be replaced by the string ``An empty string (''``)''.
print $error->pretty_format;
Get a nicely formatted string containing information about the exception. Format is similar to that produced by Bionanny::Base::throw(), with the addition of the name of the exception class in the EXCEPTION line and some other data available via the Error object.
catch Bionanny::Exception with {
my $error = shift;
print "$error";
}
Overrides Error::stringify() to call pretty_format(). This is
called automatically when an exception object is placed between double
quotes.