p4luch has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm quite new to programming in Perl and need help. I have script which downloads data from web server through function from external module. In case of errors (like 500 read timeout) function generates warning. Is it possible to catch this warning in my main script? I've tried to use eval{} on function call but it didn't seem to work. Sorry for not specyfing. I'm using BioMart Perl API to download data from EnsEMBL BioMart mirror. And code for function which downloads data by default isn't avaible for user. Piece of code which generetes warning looks like that:
And I'm intrested "catching" warning from last warn().But I have to do it in my main script.my $ua = LWP::UserAgent->new; $ua->timeout(20); # default is 180 seconds $ua->proxy( ['http', 'https'], $self->proxy ) if defined $self->pr +oxy; my $response = $ua->request($request); my @results; if ($response->is_success) { my @arr=split(/\n/,$response->content); # much neater to use 'cont +ent' instead of 'as_string', we don't need to explicitly ignore heade +r part of the http response any more. foreach my $el(@arr){ $logger->warn("RESPONSE: $el"); push (@results,$el); } } else { warn ("\n\nProblems with the web server: ". $response->status_line."\n\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Catch warning from external module
by marto (Cardinal) on Jul 18, 2014 at 08:47 UTC | |
by tbone654 (Beadle) on Jul 19, 2014 at 03:41 UTC | |
|
Re: Catch warning from external module
by Anonymous Monk on Jul 18, 2014 at 08:50 UTC | |
|
Re: Catch warning from external module
by Athanasius (Archbishop) on Jul 18, 2014 at 16:00 UTC |