For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > Program is exiting on a failure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Program is exiting on a failure
Chris Lyon

2005-08-25, 9:55 pm

I seem to be erroring out @ the $session->login portion of my program
because the module that I am call is saying the password/username is
bad. How do I trap the error and exit cleanly without just dumping
from the application:


login failed: access denied or bad username at ./cisco.pl line 47

$session =3D Net::Telnet::Cisco->new(Host =3D> $ip);
$session->login($login, $password);
Wiggins d'Anconia

2005-08-25, 9:55 pm

Chris Lyon wrote:
> I seem to be erroring out @ the $session->login portion of my program
> because the module that I am call is saying the password/username is
> bad. How do I trap the error and exit cleanly without just dumping
> from the application:
>
>
> login failed: access denied or bad username at ./cisco.pl line 47
>
> $session = Net::Telnet::Cisco->new(Host => $ip);
> $session->login($login, $password);
>


You may want to check the 'errmode' method of Net::Telnet. Otherwise you
can catch the die in the normal Perl exception handling way,

perldoc -f eval

my $return = eval { # some code that might die };
if ($@) {
print "Uh oh, croaked leaving only: $@";
}

# code after not croaking

http://danconia.org
Tom Allison

2005-08-26, 6:56 pm

Wiggins d'Anconia wrote:
> Chris Lyon wrote:
>
>
>
> You may want to check the 'errmode' method of Net::Telnet. Otherwise you
> can catch the die in the normal Perl exception handling way,
>
> perldoc -f eval
>
> my $return = eval { # some code that might die };
> if ($@) {
> print "Uh oh, croaked leaving only: $@";
> }
>
> # code after not croaking
>
> http://danconia.org
>


Personal experience says when you are doing the eval{} thing to make
sure you still have a way to die rather to the just keep plowing ahead.

As a practice, evaluate your $@ for errors you expect and then die on
all the others. This will give you a method for managing known errors
without ignoring the unexpected.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com