On Tue, 20 Nov 2001, Teggy P Veerapen wrote:
> I'm new to perl but not to programming, and I have been searching
> (without any success up to now) how perl handles errors. Does perl offer a
> system of error management ? Where can I find information (faq, URL or any
> other ...) about perl error management ?
It depends on how the function calls themselves handle errors. And for
this, you will need to consult the appropriate documentation for the
various function calls. Many system calls will return undef on an error
and put a message into $!:
open FILE, "file" or die "Can't open file: $!\n";
If you are familiar with C, this way of handling errors is similar to:
FILE *fh;
if((fh = fopen("file", "r") == NULL) {
perror("Can't open file");
}
die will end the program unless you catch it as an exception. Which
brings me to the next point, exceptions.
In Perl, you can also do exception handling with the use of eval and the
$@ variable. To use the above example:
eval {
open FILE, "file" or die "Can't open file: $!\n";
};
print "ERROR: $@" if $@;
I think there is a Throw module that lets you do exception handling in the
C++/Java style with throwing and catching.
There are also other modules that let you maniuplate warning messgaes and
handle errors for CGI programs. A good book on Perl (like the Camel) will
give you more guidance on error handling.
-- Brett
http://www.chapelperilous.net/
------------------------------------------------------------------------
He that teaches himself has a fool for a master.
-- Benjamin Franklin
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]