How to not die

B

BeHealthy

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?
 
T

Tassilo v. Parseval

Also sprach (e-mail address removed):
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
 
S

Sherm Pendley

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--
 
T

Tassilo v. Parseval

Also sprach Sherm Pendley:
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
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top