Look at eval blocks - lets you trap fatal errors from other code and not
die/abort yourself.
https://perldoc.perl.org/functions/eval.html
You can also wrie your own signal handling code
https://www.perl.com/article/37/2013/8/18/Catch-and-Handle-Signals-in-Perl/


On Wed, Aug 28, 2019 at 8:42 AM Lars Noodén <lars.noo...@gmail.com> wrote:

> I've been using the CPAN module XML::Feed to parse Atom and RSS feeds.
> Some of the feeds it fetches are a little broken  from time to time and
> when that happens the parser produces and error and stops the program.
> I'd like it to just keep going.
>
> I am invoking the parser inside a subroutine like this:
>
>         my $feed = XML::Feed->parse(URI->new($uri)) or return(0);
>
> which I thought that would allow the subroutine to simply return failure
> and let the program keep going.  But it does not.  Instead it shows an
> error and quits.  Here is an error from feed which is broken today but
> not yesterday and probably will be ok again tomorrow:
>
>         not well-formed (invalid token) at line 142, column 76,
>         byte 30070 at /usr/lib/x86_64-linux-gnu/perl5/5.24/XML/Parser.pm
>         line 187.
>
>         ... foo.pl: exited with status 255; aborting
>
> I have no control over the feeds and their formats or contents.  So, are
> there instead any recommendations on how I can have perl trap the error
> or otherwise prevent malformed XML from bringing the whole program to a
> halt?
>
> Thanks,
> Lars
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
> --
Andy Bach
afb...@gmail.com
Not at my desk

Reply via email to