By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,374 Members | 2,014 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,374 IT Pros & Developers. It's quick & easy.

Error Handling

P: 1
Hi everyone,
I'm new to perl scripting...But I managed to write a script and it is executing well.
The requirement is error management should be implemented for this script. That is
some error handling code should be included in the script so that if there is any error at any point in the script that you are expecting, it should terminate from that point.
I think we have to use trial,catch and finally blocks for this..but I'm not sure.
If anyone you guys have any idea on how to write it in the script below, please help me out.....Thanks in advance.


Expand|Select|Wrap|Line Numbers
  1. use LWP::UserAgent;
  2. $ua = LWP::UserAgent->new;
  3.  
  4. my $file = "createFile.xml";
  5. my $file_location = "C:\\Users\\rthout\\$file";
  6.  
  7.  
  8. open FILE, "<" , $file_location or die $!;
  9. while (<FILE>) {
  10.    $myrequest = $myrequest . $_;
  11. }
  12.  
  13.  
  14. my $req = HTTP::Request->new(POST => 'https://IP:Port/service/mgmt/current/');
  15. $req->content_type('text/xml');
  16. $req->content($myrequest);
  17. $req->authorization_basic('kyedaval', 'datapower007');
  18.  
  19.  
  20. my $res = $ua->request($req);
  21.  
  22. if ($res->is_success) {
  23.       print $res->as_string;
  24.       print $res->decoded_content;
  25. }
  26. else {
  27.       print "Failed: ", $res->status_line, "\n";
  28. }
Apr 21 '10 #1
Share this Question
Share on Google+
1 Reply


gpraghuram
Expert 100+
P: 1,275
HI,
May be you can check for the return value of a function and deceide to terminate or not.
To terminate you can call die "with error message " or simply exit

Raghu
Apr 22 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.