John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone have any good examples of code that is being annoyed that library functions are throwing exceptions rather than returning error codes?

In Perl 6, the caller has a choice. I want to develop some examples and meditate on that, but I have a hard time coming up with realistic examples. Personally, I don't have much problem with always "throwing" exceptions.

—John

Replies are listed 'Best First'.
Re: examples of exceptions gone wrong?
by TimToady (Parson) on Aug 31, 2008 at 00:39 UTC
    I think the main reason to convert exceptions to data is to keep parallel processes running smoothly. Exceptions tend to throw out the 99 bits of good data with the one bad bit. It's just one of those hidden gotchas that make concurrency more difficult to express than it needs to be, and we have to be all over concurrency these days.
Re: examples of exceptions gone wrong?
by betterworld (Curate) on Aug 30, 2008 at 23:40 UTC

    There are some situations where errors are not that fatal, or you even expect something to fail.

    • The MAX_TRIES loop in File::Temp: This tries some file names until open won't give EEXIST any more. Personally I often write code like this where I take advantage of the atomicity of system calls (e.g. use the fact that open tests for existence).
    • When you write a port scanner using connect calls.
    • This might qualify as well: Replace duplicate files with hardlinks (although something like "next" could be done with exceptions quite easily).