| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
CatalystX::Usul::Exception - Exception base class
0.3.$Revision: 596 $
use base qw(CatalystX::Usul);
sub some_method {
my $self = shift; my $e;
eval { this_will_fail }
$self->throw( $e ) if ($e = $self->catch);
}
Implements try (by way of an eval), throw, and catch error semantics. Inherits from Exception::Class
Catches and returns a thrown exception or generates a new exception if EVAL_ERROR has been set
warn $e->as_string( $verbosity, $offset );
Serialise the exception to a string. The passed parameters; verbosity and offset determine how much output is returned.
The verbosity parameter can be:
The default value. Only show a stack trace if $self->show_trace is true
Always show the stack trace and start at frame offset which defaults to 1. The stack trace stops when the first duplicate output line is detected
Always shows the complete stack trace starting at frame 0
Create (or re-throw) an exception to be caught by the catch above. If the passed parameter is a reference it is re-thrown. If a single scalar is passed it is taken to be an error message code, a new exception is created with all other parameters taking their default values. If more than one parameter is passed the it is treated as a list and used to instantiate the new exception. The 'error' parameter must be provided in this case
None
The $IGNORE package variable is list of methods whose presence
should be suppressed in the stack trace output
There are no known incompatibilities in this module
The default ignore package list should be configurable
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan <Support at RoxSoft.co.uk>
Copyright (c) 2008 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
# @(#)$Id: Exception.pm 596 2009-06-16 18:49:50Z pjf $ package CatalystX::Usul::Exception; use strict; use warnings; use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 596 $ =~ /\d+/gmx ); use Exception::Class ( 'CatalystX::Usul::Exception::Class' => { fields => [qw(args out rv)] } ); use base qw(CatalystX::Usul::Exception::Class); use Carp; use English qw(-no_match_vars); my $NUL = q(); our $IGNORE = [ __PACKAGE__ ]; sub catch { my ($self, @rest) = @_; my $e; return $e if ($e = $self->caught( @rest )); return $self->new( args => [], ignore_package => $IGNORE, out => $NUL, rv => 1, show_trace => 0, error => $EVAL_ERROR ) if ($EVAL_ERROR); return; } sub as_string { my ($self, $verbosity, $offset) = @_; $verbosity ||= 1; $offset ||= 1; my ($l_no, %seen); my $text = $NUL.$self->message; # I hate Return::Value return $text if ($verbosity < 2 and not $self->show_trace); my $i = $verbosity > 2 ? 0 : $offset; my $frame = undef; while (defined ($frame = $self->trace->frame( $i++ ))) { my $line = "\n".$frame->package.' line '.$frame->line; if ($verbosity > 2) { $text .= $line; next } last if (($l_no = $seen{ $frame->package }) && $l_no == $frame->line); $seen{ $frame->package } = $frame->line; } return $text; } sub throw { my ($self, @rest) = @_; croak $rest[0] if ($rest[0] and ref $rest[0]); my @args = @rest == 1 ? ( error => $rest[0] ) : @rest; croak $self->new( args => [], ignore_package => $IGNORE, out => $NUL, rv => 1, show_trace => 0, @args ); } 1; __END__
# Local Variables: # mode: perl # tab-width: 3 # End: