Posted on 2006-03-04 10:10:27-08 by pandur
Preventing WWW::Mechanize from aborting the whole script
How do I prevent WWW::Mechanize to abort the whole script if it encounters an error, for example if I try to fill in a form and it doens't find a given field it aborts the whole script.
Direct Responses: 1897 | Write a response
Posted on 2006-03-04 14:15:36-08 by cjara in response to 1896
Re: Preventing WWW::Mechanize from aborting the whole script
I made a test program and it works redirecting the error to a function: $SIG { __DIE__ } = \&myerror; sub myerror { ... }
Direct Responses: 1900 | Write a response
Posted on 2006-03-05 16:55:16-08 by pandur in response to 1897
Re: Preventing WWW::Mechanize from aborting the whole script
Thanks for your reply, but I'm a bit of a perl newbie, so can you please give me a small example. I tried to declare to declare $SIG { __DIE__ } = \&myerror; at the beginning but it didn't work.
Direct Responses: 1902 | Write a response
Posted on 2006-03-06 12:56:33-08 by cjaramilu in response to 1900
Re: Preventing WWW::Mechanize from aborting the whole script
Other suggestion:
You can catch the error without aborting the script
by wrapping the submit_form imside an eval block.
eval { $mech->submit_form ( form_number => 1 , fields => { foo => "bar" } ); }; if ( $@ ) { # error print "error ($@) "; } else { # success $c = $mech->content; print $c; }
Direct Responses: 1905 | Write a response
Posted on 2006-03-06 18:44:31-08 by pandur in response to 1902
Re: Preventing WWW::Mechanize from aborting the whole script
Thanks, Cjara, works great.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.