In article <11**********************@g14g2000cwa.googlegroups .com>,
Babu <ba****************@gmail.com> wrote:
Hi,
I am a Perl newbie and have a doubt on Perl exception handling.
My understanding regarding exception handling is execute a piece of
code, if any exception occurs, handle the exception and proceed as if
the error never occurred at all.
So code would look like
Eval {
It's 'eva'. Case matters.
# do something
}; if ($@)
{
#handle exception
}
#procees as if no exception occurred
But in Perl I find that very often we die upon an exception. We never
try to handle the exception and continue. Is my understanding correct?
Is this the right way to do it?
The 'right way' to do it depends upon the application. I myself don't
use the eval { } method for trapping exceptions, because almost all of
the Perl programs I write are used by me and noboby else. Most of the
fatal errors in my Perl programs are caused by bad input or unforeseen
circumstances. When I encounter a fatal error, I analyze the cause and
modify my program to handle it.
On the other hand, were I writing programs for a production environment
in which the programs were used by others, I would pay much more
attention to trapping these unforeseen circumstances and dealing with
them somehow.
FYI: this newsgroup is defunct; try comp.lang.perl.misc in the future.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---