Doubt in Perl exception handling

Discussion in 'Perl' started by Babu, Mar 10, 2005.

  1. Babu

    Babu Guest

    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
     
    Babu, Mar 10, 2005
    #1
    1. Advertising

  2. Babu

    Jim Gibson Guest

    In article <>,
    Babu <> 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 =---
     
    Jim Gibson, Mar 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Nelson

    doubt about doubt

    Bob Nelson, Jul 28, 2006, in forum: C Programming
    Replies:
    11
    Views:
    626
  2. Simbolla Simbolla

    Doubt regarding Exception handling in Watir

    Simbolla Simbolla, May 3, 2010, in forum: Ruby
    Replies:
    0
    Views:
    204
    Simbolla Simbolla
    May 3, 2010
  3. Replies:
    0
    Views:
    565
  4. Peter Otten
    Replies:
    2
    Views:
    117
    Cousin Stanley
    Aug 10, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    120
    Terry Reedy
    Aug 10, 2013
Loading...

Share This Page