in reply to Programming style question on where to use die

I'd use an error return value when an error return is a "normal" return. That is, a good portion of the time when the routine is called, it returns the "something went wrong" value.

I'd use an exception mecanism if the error is unexpected or rare, or it'd be difficult to test in normal usage. For example, the HTML generation functions of CGI.pm would be incredibly awkward to use if they had an error return value, because you'd be forever storing the result, testing it, and then moving along if it wasn't an error.

Just my 2-ish cents. {grin}

-- Randal L. Schwartz, Perl hacker

  • Comment on Re: Programming style question on where to use die