| 1 | # You may distribute under the terms of either the GNU General Public License | ||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||
| 3 | # | ||
| 4 | # (C) Paul Evans, 2006,2009 -- leonerd@leonerd.org.uk | ||
| 5 | |||
| 6 | package Error::SystemException; | ||
| 7 | |||
| 8 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 1 | ▶ | use base qw( Error ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 1 | our $VERSION = '0.05'; | |
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | C<Error::SystemException> - an L<Error> subclass to represent OS-thrown | ||
| 18 | errors. | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | This exception is used to indicate errors returned by the operating system, or | ||
| 23 | underlying libraries. As well as a string error message, it also contains the | ||
| 24 | string form of C<$!> at the time the exception was thrown. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | =head1 FUNCTIONS | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | =head2 $e = Error::SystemException->new( $message ) | ||
| 33 | |||
| 34 | This function constructs a new exception object and returns it. Normally this | ||
| 35 | function should not be necessary from most code, as it would be constructed | ||
| 36 | during the C<< Error->throw() >> method. | ||
| 37 | |||
| 38 | throw Error::SystemException( "Something went wrong" ); | ||
| 39 | |||
| 40 | The value of C<$message> is passed as the C<-text> key to the superclass | ||
| 41 | constructor, and the numerical value of C<$!> at the time the exception object | ||
| 42 | is built is passed as the C<-value> key. The string value of C<$!> is also | ||
| 43 | stored in the object. | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub new | ||
| 48 | 1 | ▶ | { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 49 | 1 | my $class = shift; | |
| 50 | 1 | my $perror = "$!"; | |
| 51 | 1 | my $errno = $!+0; | |
| 52 | |||
| 53 | 1 | my ( $message ) = @_; | |
| 54 | |||
| 55 | 1 | local $Error::Depth = $Error::Depth + 1; | |
| 56 | |||
| 57 | 1 | my $self = $class->SUPER::new( -text => $message, -value => $errno ); | |
| 58 | |||
| 59 | 1 | $self->{perror} = $perror; | |
| 60 | |||
| 61 | 1 | $self; | |
| 62 | } | ||
| 63 | |||
| 64 | =head2 $str = $self->perror | ||
| 65 | |||
| 66 | This function returns the stored string value of Perl's C<$!> variable at the | ||
| 67 | time the exception object was created. | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | sub perror | ||
| 72 | 3 | ▶ | { |
|
Subroutine
perror: called CC=1 SCAR=0.0
Pod
documented
| |||
| 73 | 3 | my $self = shift; | |
| 74 | 3 | return $self->{perror}; | |
| 75 | } | ||
| 76 | |||
| 77 | sub stringify | ||
| 78 | 2 | ▶ | { |
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||
| 79 | 2 | my $self = shift; | |
| 80 | 2 | return $self->SUPER::stringify() . " - " . $self->perror; | |
| 81 | } | ||
| 82 | |||
| 83 | # Keep perl happy; keep Britain tidy | ||
| 84 | 1 | 1; | |
| 85 | |||
| 86 | __END__ | ||