NAME
Error::SystemException
- an Error subclass to represent OS-thrown errors.
DESCRIPTION
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.
FUNCTIONS
$e = Error::SystemException->new( $message )
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.
$str = $self->perror
This function returns the stored string value of Perl's $!
variable at the time the exception object was created.
EXAMPLES
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...
};
SEE ALSO
Error - Base module for exception-based error handling
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>