How to not die

Discussion in 'Perl Misc' started by BeHealthy@gmail.com, Oct 9, 2005.

  1. Guest

    I am using XML::RSS module to parse lots of RSS files in batch. However
    if one of the RSS files has invalid format, then a die call is thrown
    from the parser. Is there any way I can handle the die call, so that
    the program can keep running by skipping the invalid RSS file?
    , Oct 9, 2005
    #1
    1. Advertising

  2. Also sprach :

    > I am using XML::RSS module to parse lots of RSS files in batch. However
    > if one of the RSS files has invalid format, then a die call is thrown
    > from the parser. Is there any way I can handle the die call, so that
    > the program can keep running by skipping the invalid RSS file?


    Use a BLOCK-eval (not to be confused with STRING-eval):

    eval {
    # code that potentially dies
    }
    if ($@) {
    print "Code died with message '$@'";
    }

    Tassilo
    --
    use bigint;
    $n=71423350343770280161397026330337371139054411854220053437565440;
    $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
    Tassilo v. Parseval, Oct 9, 2005
    #2
    1. Advertising

  3. "" <> writes:

    > Is there any way I can handle the die call


    Wrap your code in a block eval() - not to be confused with a string eval().
    eval() returns undef on failure, and you can check $@ for the message given
    to die(). For instance:

    # Not a complete program, obviously...
    eval {
    do_something();
    } or {
    warn $@ if $@;
    }

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Oct 9, 2005
    #3
  4. Also sprach Sherm Pendley:

    > "" <> writes:
    >
    >> Is there any way I can handle the die call

    >
    > Wrap your code in a block eval() - not to be confused with a string eval().
    > eval() returns undef on failure, and you can check $@ for the message given
    > to die(). For instance:
    >
    > # Not a complete program, obviously...
    > eval {
    > do_something();
    > } or {
    > warn $@ if $@;
    > }


    Depending on do_something's return value, this might still execute the
    or-branch. I'd rather write this as:

    eval {
    do_something();
    1;
    } or warn $@;

    Tassilo
    --
    use bigint;
    $n=71423350343770280161397026330337371139054411854220053437565440;
    $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
    Tassilo v. Parseval, Oct 9, 2005
    #4
    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. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    413
    Natty Gur
    Jan 26, 2004
  2. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    432
    Alvin Bruney
    Jan 25, 2004
  3. John Benson
    Replies:
    1
    Views:
    341
    Hoang
    Jan 15, 2004
  4. Replies:
    1
    Views:
    853
    Thomas Hawtin
    Sep 18, 2006
  5. Guest
    Replies:
    1
    Views:
    127
    Guest
    Aug 7, 2004
Loading...

Share This Page