Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to not die

Reply
Thread Tools

How to not die

 
 
BeHealthy@gmail.com
Guest
Posts: n/a
 
      10-09-2005
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?

 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      10-09-2005
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=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      10-09-2005
"" <> 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
 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      10-09-2005
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=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
re: @Don postet euch den Film des Jahres " Die rache der Sith " in MVCD (028/110] - "Star Wars Episode 3 - Die Rache der Sith ( 1_2 MVCD ) ein @Don post.part28.rar" Marco Computer Support 0 05-22-2005 01:25 PM
Die IDE Die Lloyd Sheen ASP .Net 2 01-26-2004 04:59 AM
More Die IDE Die Lloyd Sheen ASP .Net 5 01-25-2004 02:34 PM
I want to be a hacker/nerd b4 I die. Ghost issues (now and after I die) O.Phooey Computer Support 4 07-05-2003 08:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57