Forum Discussion
Charles_Harris
Nimbostratus
Jan 13, 2006Perl Scripting (iControl) error handling...
Hi All,
I'm currently writting my first iControl based app using perl to monitor / react to a very simple scenario but I've come across a problem and I'm stumped.....
How can I handle errors, without the perl script stopping? - I need to be able to output friendly error messages and log them for further investigation....
eg. Wrong login credentials supplied etc.....
Thanks in advance!
-=ChaZ=-
4 Replies
- The only way I know how to do is is by wrapping the code with an eval
http://perldoc.perl.org/functions/eval.html
Click here
Here's some sample code showing how you can use it:---------------------------------------------------------------------------- listPools ---------------------------------------------------------------------------- sub listPools() { eval { $soapResponse = $Pool->get_list(); }; if ( $@ ) { print "Error occurred\n"; print "Error details: $@\n"; } else { &checkResponse($soapResponse); my @pool_list = @{$soapResponse->result}; print "Available Pools:\n"; foreach $pool (@pool_list) { print " $pool\n"; } } }
-Joe - Charles_Harris
Nimbostratus
Hi Joe,
Thanks for the tip, I must admit, I've seen this approach used in some other sample code although I wasn't overly sure how to implement it around the various Soap calls.
I'll give it a try and see how I get on!
Ps. I'm fairly new to Perl and iControl so the code sample is most welcome!!
Cheers!
-=ChaZ=- - Charles_Harris
Nimbostratus
Hi again......
Please could you give me an example of how to wrap the Auth in the eval statements you previously mentioned?
Currently mine looks like this....
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$USER" => "$PASSWORD";
}
But I'm not sure how to do the error bit.....
Thanks in advance !!!
Cheers,
-=ChaZ=- - I gave you an example in my post above. You wrap an eval around the method call.
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
