Cannot catch exception on method $mech->field()

49 views
Skip to first unread message

Eric Smith

unread,
Apr 17, 2012, 10:24:12 AM4/17/12
to www-mecha...@googlegroups.com
Hi

I am looping through a number of queries and when there is an
exception I never want the script to die but to continue looping.

Accordingly, I am using autocheck => 0 in calls like the following line [60]:

$return_value = $mech->field ('ctl00$ctl00$ContentPlaceHolderContent$ContentPlaceHolderMenuAreaLeft$DeviceSearchByCode1$TabDeviceSearchByDeviceCode$TabPanelSearchFilterByDeviceCode$DeviceFilterByDeviceCodeWithNotAct$TbDeviceCode' => '%', autocheck => 0 );

Despite this however, my script fails sporadically with the
following stacktrace;

Uncaught exception from user code:
Can't call method "value" on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1403.
at /usr/share/perl5/WWW/Mechanize.pm line 1403
WWW::Mechanize::field('WWW::Mechanize=HASH(0x996abc8)', 'ctl00$ctl00$ContentPlaceHolderContent$ContentPlaceHolderMenuA...', '%', 'autocheck', 0) called at /home/eric/bin/zenatek_login.pl line 60

How may I catch this exception and prevent the script from die-ing?

--
- Eric Smith

Andy Lester

unread,
Apr 20, 2012, 1:07:46 AM4/20/12
to www-mecha...@googlegroups.com
> Accordingly, I am using autocheck => 0 in calls like the following line [60]:

autocheck is only meaningful in the constructor. It turns off checks on HTTP requests. It has nothing to do with fields.


> Uncaught exception from user code:
> Can't call method "value" on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1403.
> at /usr/share/perl5/WWW/Mechanize.pm line 1403
> WWW::Mechanize::field('WWW::Mechanize=HASH(0x996abc8)', 'ctl00$ctl00$ContentPlaceHolderContent$ContentPlaceHolderMenuA...', '%', 'autocheck', 0) called at /home/eric/bin/zenatek_login.pl line 60


For that, you need to look at the eval function. See perldoc -f veal.

xoa

--
Andy Lester => an...@petdance.com => www.petdance.com => AIM:petdance

Eric Smith

unread,
Apr 28, 2012, 11:49:20 AM4/28/12
to www-mecha...@googlegroups.com
Thanks Andy - all cooking.
Reply all
Reply to author
Forward
0 new messages