Error::SystemException - an Error subclass to represent OS-thrown errors.
Error::SystemException
This exception is used to indicate errors returned by the operating system, or underlying libraries. As well as a string error message, it also contains the string form of $! at the time the exception was thrown.
$!
This function constructs a new exception object and returns it. Normally this function should not be necessary from most code, as it would be constructed during the Error->throw() method.
Error->throw()
throw Error::SystemException( "Something went wrong" );
The value of $message is passed as the -text key to the superclass constructor, and the numerical value of $! at the time the exception object is built is passed as the -value key. The string value of $! is also stored in the object.
$message
-text
-value
This function returns the stored string value of Perl's $! variable at the time the exception object was created.
Typically, this exception class would be used following the failure of a system call.
mkdir( $dir ) or throw Error::SystemException( "Cannot mkdir( '$dir' )" );
If caught, this exception would print a message perhaps looking like
Cannot mkdir( '/root/testdir' ) - Permission denied
Because it is a subclass of Error, the usual try/catch mechanisms also apply to it.
Error
try { mkdir( $dir ) or throw Error::SystemException( "mkdir($dir)" ); try { chmod( $mode, $dir ) or throw Error::SystemException( "chmod($dir)" ); chown( $uid, $gid, $dir ) or throw Error::SystemException( "chown($dir)" ); } catch Error with { my $e = shift; rmdir( $dir ); $e->throw; }; } catch Error with { my $e = shift; # handle $e here... };
Error - Base module for exception-based error handling
Paul Evans <leonerd@leonerd.org.uk>
To install Error::SystemException, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Error::SystemException
CPAN shell
perl -MCPAN -e shell install Error::SystemException
For more information on module installation, please visit the detailed CPAN module installation guide.