Error Handling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GKReddy
    New Member
    • Apr 2010
    • 1

    Error Handling

    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.


    Code:
    use LWP::UserAgent;
    $ua = LWP::UserAgent->new;
    
    my $file = "createFile.xml";
    my $file_location = "C:\\Users\\rthout\\$file";
    
    
    open FILE, "<" , $file_location or die $!;
    while (<FILE>) {
       $myrequest = $myrequest . $_;
    }
    
    
    my $req = HTTP::Request->new(POST => 'https://IP:Port/service/mgmt/current/');
    $req->content_type('text/xml');
    $req->content($myrequest);
    $req->authorization_basic('kyedaval', 'datapower007');
    
    
    my $res = $ua->request($req);
    
    if ($res->is_success) {
          print $res->as_string;
          print $res->decoded_content;
    }
    else {
          print "Failed: ", $res->status_line, "\n";
    }
    Last edited by eWish; Apr 22 '10, 01:58 AM. Reason: Please use the code tags
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    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

    Comment

    Working...