Thread

Posted on Sat Jun 24 04:29:45 2006 by mnp
croak and die in a library: is it a good thing?
Hi folks, Philosophy question for you. Is it a good idea to carp in a CPAN package? If the caller does not want this behavior, it needs to register a die handler, which can be inconvenient since the stack gets unwound. I very much prefer Net-SSH2's "return false, then call error()" methodology, but it's not used everywhere. In particular, I really want to do the following, but the carps inside the library get in the way:
my $ssh = Net::SSH2->new(); for my $host (@hosts) { if ($ssh->connect($host)) { # use connnection } else { my ($code, $error_name, $error_string) = $ssh->error; # handle bad host } }
If I have to do the eval{} and $SIG{__DIE__} thing, it's much more of a hassle. Would anyone mind if I converted all the carps to the already-semi-standard:
$self->error(0, "oops"); return;
Thanks for reading, - Mitch
Direct Responses: 4412 | Write a response
Posted on Sat Feb 24 19:14:48 2007 by dbrobins in response to 2527
Re: croak and die in a library: is it a good thing?
I looked through the code and this is the only runtime croak/die in it (i.e. the others are clear programmer error e.g. wrong number of parameters or other bad input). I'm willing to change it to return a false value on failure; if you're still interested, please file a bug on rt.cpan.org.
Write a response