in reply to Re: Re: multiple db connects
in thread multiple db connects

Sure, you could do whatever you wanted, really. Personally I like to die when something seems like an obviously fatal error. That doesn't mean that your *program* will die, because you can catch the die in an eval block. Which is what I do.

You also said:

> The die clause still returns > a false value for the sub call, right?
Well, no; the die just *dies*. Your sub won't return at all. Your program will die, unless you have an eval block, in which case the die will shoot you out to the closest eval block, and will populate $@ with the error message. And then you said:
> But this could cause > errors if not handled in the main clause, right?
Certainly. That's why the errors should be handled. :)

Instead of dying, then, you could have your sub return a false value. That would work. Then you could do your checking out in the caller. Some people find that preferable, I'm sure, and that's fine; my preference is to throw exceptions as soon as something bad happens. Then I catch them.

Replies are listed 'Best First'.
Re: Re: Re: Re: multiple db connects
by ichimunki (Priest) on Dec 21, 2000 at 21:45 UTC
    So that's the behavior I'm trying to understand about die. If it is going to cause the program to bomb, then it seems like (especially for CGI) a much better idea to me (both in terms of user-friendly solutions and in terms of code re-usability) to build the function in such a way that it returns a false value if it fails. That way the function doesn't kill the whole process (i.e. HTTP result code 500) and it can be used in statements like
    $foo = biff($bap) || 'Bar'; or if ($dbh = handle($db)) { do_something($dbh); } else { dont(); }
    (for instance).