|
Exception::System - The exception class for system or library calls |
Exception::System - The exception class for system or library calls
# Loaded automatically if used as Exception::Base's argument
use Exception::Base ':all',
'Exception::System',
'Exception::File' => { isa => 'Exception::System' };
try eval {
my $file = "/notfound";
open FILE, $file
or throw Exception::File message=>"Can not open file: $file",
file=>$file;
};
if (catch Exception::System my $e) {
if ($e->isa('Exception::File')) { warn "File error:".$e->{errstr}; }
if ($e->with(errname=>'ENOENT')) { warn "Caught not found error"; }
}
This class extends standard the Exception::Base manpage with handling system or library errors. The additional fields of the exception object are filled on throw and contain the error message and error codes.
Class fields are implemented as values of blessed hash.
eval { throw Exception::System message=>"Message"; };
catch Exception::System my $e
and print $e->{errstr};
eval { throw Exception::System message=>"Message"; };
catch Exception::System my $e and $e->{errstros} ne $e->{errstr}
and print $e->{errstros};
eval { throw Exception::System message=>"Message"; };
eval { throw Exception::System message=>"Message"; };
catch Exception::System my $e and $e->{errname} eq 'ENOENT'
and $e->throw;
eval { open F, "/notexisting"; throw Exception::System; };
print $@->stringify(1);
print "$@";
The module was tested with the Devel::Cover manpage and the Devel::Dprof manpage.
If you find the bug, please report it.
Piotr Roszatycki <dexter@debian.org>
Copyright (C) 2007 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
|
Exception::System - The exception class for system or library calls |