SPUG: Trapping LWP exceptions

Sanford Morton smorton at pobox.com
Mon Sep 11 10:32:30 CDT 2000

I need to trap certain LWP exceptions. Is it more appropriate to
handle the __DIE__ signal or use an eval block on $ua->request($req)?

I'm using LWP and a user agent to repeatedly poll a web page looking
for updates:

    while (sleep 900) {
      $resp = $ua->request($req);
      &process_page( $resp->as_string );  

Occasionally the script dies with errors like

   500 (Internal Server Error) Can't connect to www.yahoo.com:80
   (Transport endpoint is not connected) Client-Date: Mon, 11 Sep 2000
   14:43:28 GMT

I think these are server hiccups, going offline for seconds or a few
minutes, so that the socket fails to connect. The user agent is
die'ing deep within LWP, maybe LWP::Protocol::http or IO::Socket.

I'd like to trap these exceptions, to go to sleep and try again later,
instead of die'ing. What's the best way to do that? Shall I handle the
__DIE__ signal or use an eval block on $ua->request($req)? It's not
clear to me what the difference is between these or which is more
appropriate in this instance.

Sandy Morton

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

More information about the spug-list mailing list