use Error;
package MyPackage;
@ISA = qw(Error::Methods);
sub new {
...
...
$obj = some_function() or
return MyPackage->Error(100,"Construction failed");
}
Error package provides an object which can be used to pass details about errors
back to the user, without actually having to return the error object.
The use of Error also defines a second package Error::Methods. This package defines methods, that can be inherited by other object
packages, to ease the creation of Error objects.
There are three ways in which an previous error can be obtained.
$@ will contain the last error raised by the Error package providing no other
event has happened to cause perl to overwrite $@.
my $obj = new SomeObject or
die SomeObject->Error;