[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

prevent script from dying

Posted on 2007-08-12
4
Medium Priority
?
205 Views
Last Modified: 2013-11-05
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
Comment
Question by:mypatek
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
mjcoyne earned 100 total points
ID: 19680446
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
 

Author Comment

by:mypatek
ID: 19680519
just added the returns, but no difference.. any other suggestions?
0
 
LVL 25

Assisted Solution

by:clockwatcher
clockwatcher earned 100 total points
ID: 19681151
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
 

Author Comment

by:mypatek
ID: 19688223
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question