Thread

Posted on Sat Mar 4 12:10:27 2006 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 Sat Mar 4 16:15:36 2006 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 Sun Mar 5 18:55:16 2006 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 Mon Mar 6 14:56:33 2006 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 Mon Mar 6 20:44:31 2006 by pandur in response to 1902
Re: Preventing WWW::Mechanize from aborting the whole script
Thanks, Cjara, works great.
Write a response