Throwable::SysError - a sub-class of Throwable::Error for system error objects
package MyApp::SysError; use Moo; extends qw( Throwable::SysError ); has path => ( is => 'ro', required => 1 ); ... open my $fh, '<', $file or MyApp::SysError->throw({ message => 'open() failed', op => 'open', path => $file }); ... try { mkdir $dir or MyApp::SysError->throw( message => 'mkdir() failed', op => 'mkdir', path => $dir ); ... } catch { # ignore errors if making a directory that already exists return if $_->op eq 'mkdir' && $_->is( 'EEXIST' ); $logger->log->error( 'unrecoverable system error: ', $_->op, ': ', $op->path, ': ', $op->errstr ); $_->throw; };
Throwable::SysError is a simple class for exceptions that will be thrown to signal errors related to system functions like open() or anything that sets $! when an operation fails. It is built on top of Throwable::Error as a sub-class which you can use directly or by sub-classing it yourself for your specific needs.
open()
$!
Throwable::Error
This attribute is required and should contain a string describing the operation that caused the error.
This attribute is not meant to be set directly and if not provided is derived from the numeric value of $! at the time the exception is thrown. If you need to provide a value for this attribute manually, you can use "_errno" in calls to new()/throw().
"_errno"
new()
throw()
This attribute is not meant to be set directly and if not provided is derived from the string value of $! at the time the exception is thrown. If you need to provide a value for this attribute manually, you can use "_errno" in calls to new()/throw().
Returns true if the error constant named in $constant represents the current errno. This allows you to test for specific error conditions in your exception handlers without needing to import constants from Errno.
$constant
Errno
This module is a sub-class of Throwable::Error.
jason hord <pravus@cpan.org>
Copyright (c) 2013, jason hord
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
To install Throwable::SysError, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Throwable::SysError
CPAN shell
perl -MCPAN -e shell install Throwable::SysError
For more information on module installation, please visit the detailed CPAN module installation guide.