Doubt in Perl exception handling

B

Babu

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 {
# 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?

TIA,
Babu
 
J

Jim Gibson

Babu said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top