Exception::System - The exception class for system or library calls
# The simplest usage use Exception::Base 'Exception::System'; open my $file, "/notfound" or Exception::System->throw(message=>"Can not open file"); # The Exception::System class can be a base class for others # # Loaded automatically if used as Exception::Base's argument use Exception::Base, 'Exception::System', 'Exception::File' => { isa => 'Exception::System', has => 'filename', string_attributes => [ 'message', 'errstr', 'filename' ], }; eval { my $filename = "/notfound"; open my $fh, $filename or Exception::File->throw( message=>"Can not open file", filename=>$filename, ); }; if ($@) { my $e = Exception::Base->catch; if ($e->isa('Exception::File')) { warn "File error:".$e->errstr; } if ($e->matches({errname=>'ENOENT'})) { warn "Caught not found error"; } }
This class extends standard Exception::Base with handling system or library errors. The additional attributes of the exception object are filled on throw and contain the error message and error codes.
Exception::Base
Declaration of class attributes as reference to hash.
See Exception::Base for details.
Class attributes are implemented as values of blessed hash. The attributes of base class are inherited. See Exception::Base to see theirs description.
Contains the message of the exception. This class overrides the default value from Exception::Base class.
Contains the system error string fetched at exception throw. It is the part of the string representing the exception object. It is the same as $! variable in string context.
$!
eval { Exception::System->throw( message=>"Message" ) }; my $e = Exception::Base->catch and print $e->errstr;
Contains the extended system error string fetched at exception throw. It is the same as $^E variable.
$^E
eval { Exception::System->throw( message=>"Message" ); }; if ($@) { my $e = Exception::Base->catch; if ($e->errstros ne $e->errstr) { print $e->errstros; } }
Contains the system error number fetched at exception throw. It is the same as $! variable in numeric context. This attribute represents numeric value of the exception object in numeric context.
use Errno (); eval { Exception::System->throw( message=>"Message" ); }; if ($@) { my $e = Exception::Base->catch; if ($e->errno == &Errno::ENOENT) { # explicity warn "Not found"; } elsif ($e == &Errno::EPERM) { # numeric context warn "Bad permissions"; } }
Contains the system error constant from the system error.h include file.
eval { Exception::System->throw( message=>"Message" ); }; my $e = Exception::Base->catch and $e->errname eq 'ENOENT' and $e->throw;
Meta-attribute contains the format of string representation of exception object. This class overrides the default value from Exception::Base class.
Meta-attribute contains the name of the attribute which contains numeric value of exception object. This class overrides the default value from Exception::Base class.
Collect system data and fill the attributes of exception object. This method is called automatically if exception if throwed. This class overrides the method from Exception::Base class.
Exception::Base.
If you find the bug, please report it.
Piotr Roszatycki <dexter@debian.org>
Copyright (C) 2007, 2008 by Piotr Roszatycki <dexter@debian.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Exception::System, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Exception::System
CPAN shell
perl -MCPAN -e shell install Exception::System
For more information on module installation, please visit the detailed CPAN module installation guide.