incognito129 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script using www::mechanize to fetch a few pages. However sometimes the sites are down and after mechanize timeouts on the site it exits completely instead of moving on. How do I get mechanize to not quit and continue on?
  • Comment on stopping www::mechanize from exiting after a timeout

Replies are listed 'Best First'.
Re: stopping www::mechanize from exiting after a timeout
by Corion (Patriarch) on Aug 14, 2009 at 06:41 UTC
Re: stopping www::mechanize from exiting after a timeout
by Anonymous Monk on Aug 14, 2009 at 07:29 UTC
    You can catch die's with eval {}, example
    #!/usr/bin/perl -- use strict; use warnings; use WWW::Mechanize; my $ua = WWW::Mechanize->new( autocheck => 1 ); for ( 1, 6 ){ eval { $ua->get('die://die'); 1 } or print "$@\n"; } __END__ Error GETing die://die: Protocol scheme 'die' is not supported at - li +ne 9 Error GETing die://die: Protocol scheme 'die' is not supported at - li +ne 9
    Or turn autocheck off, and do your own checking.
Re: stopping www::mechanize from exiting after a timeout
by desemondo (Hermit) on Aug 14, 2009 at 06:48 UTC
    Based on the very limited info you've provided - its a bit hard to provide much help.

    Maybe consider:
    1. Paste your code thats 'exiting'
    2. Provide the specific output thats being generated, or specificy at what point your code is exiting.

    At a guess, it might be due to an exception thats being thrown in one of the modules that www::mechanize uses. If so, you can neutralise it via a block eval.