http://www.perlmonks.org?node_id=797465


in reply to WWW::Mechanize follow_link() crashes if no link is found

It's seems to me it's a feature actually and not a bug. Quote from the Changes for version 1.51_03:
$mech->follow_link() did not complain if a link could not be found, even with autocheck on. Now it does. Thanks, Flavio Poletti.

Replies are listed 'Best First'.
Re^2: WWW::Mechanize follow_link() crashes if no link is found
by venkatesan_G02 (Sexton) on Sep 25, 2009 at 11:54 UTC
    Hi,

    First thanks for the reply.

    But, Pardon me for my ignorance. I didn't get your point.

    Is there any way to make my program move on with the next step rather than crashing at follow_link line?

    Thanks
      Is there any way to make my program move on with the next step

      If all else fails, you could trap the exception, i.e. wrap the call within eval { ... } — Something like this

      my $foo; # undefined eval { $foo->url(); # would 'Can't call method "url" on an undefined val +ue ...' }; if ($@) { # ... handle the exception print "error: ...: $@\n"; }
        Thanks almut.... It worked.
      Well, one way would be to always pass a valid link to be followed. The other would be, as is specified in the WWW::Mechanize docs, to set autocheck to 0. Although, this would silence all requests unless they're errors.