Error::SystemException - an the Error manpage subclass to represent OS-thrown
errors.
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.
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.
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.
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...
};
the Error manpage - Base module for exception-based error handling
Paul Evans <leonerd@leonerd.org.uk>