• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

prevent script from dying

The following snippet works well to display error messages during xml-RPC transfers (thanks clockwatcher)
How can I prevent a script from dying when an error occurs? In a following step it should print the rest of the html code (to properly print the html page

my $cli = RPC::XML::Client->new($server, combined_handler => \&problems);
sub problems {
      my $problem = shift;
      my $problemtype = ref($problem);

      if ($problemtype eq "RPC::XML::fault") {
            print "Fault: ".$problem->code()." -- ".$problem->string()."\n";
      } else {
            print "Problem: $problem\n";
      }
}
0
mypatek
Asked:
mypatek
  • 2
2 Solutions
 
mjcoyneCommented:
my $cli = RPC::XML::Client->new($server, combined_handler => \&problems);

sub problems {
      my $problem = shift;
      my $problemtype = ref($problem);

      if ($problemtype eq "RPC::XML::fault") {
            print "Fault: ".$problem->code()." -- ".$problem->string()."\n";
            return;
      } else {
            print "Problem: $problem\n";
            return;
      }
}

Maybe?
0
 
mypatekAuthor Commented:
just added the returns, but no difference.. any other suggestions?
0
 
clockwatcherCommented:
Without digging into the XML::RPC documentation, I'd try this:

   my $cli = RPC::XML::Client->new($server, combined_handler => \&problems);

   my $req = RPC::XML::request->new('data.getClients', RPC::XML::struct->new( rows => 1000,  languagecode => 'en', offset => $offset ));
     
   my $resp;
   eval { $resp = $cli->simple_request($req); };
   if ($@) {
      # request had some problems
   } else {
      # request was successful
   }
0
 
mypatekAuthor Commented:
hi clockwatcher,

i run the script with "warnings on" from shell and with parameters to force this xml fault:

Can't use an undefined value as an ARRAY reference at search.pl line 201.

Line 201 is the following:       for my $row (@{$resp}) {

If I remove this loop, the script runs through. How can I avoid this abord? The near environment is as follow:
      my $resp = $cli->simple_request($req);

      if (@{$resp}) {

      for my $row (@{$resp}) {

      my $rowref1=$dbh->selectall_arrayref("
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now