|
On Sep 17, 2014, at 9:18 PM, Andrew Starks <andrew.starks@trms.com> wrote:
This whole thing is a horribly gray area (witness pretty much every single computer language). To my mind the nearest you can get is distinguishing between “expected” and “unexpected” conditions in a program (which is, of course, itself horribly vague). For “expected” conditions, I prefer to use some kind of return value, while for unexpected conditions I use some kind of exception/throw mechanism. Example: FileOpen() fails because the file is not found. For me this is in the “return an error” bucket, since a program should always have code to cope with this, and that code should live close to where the file was opened. Example: Out of memory error. This is an exception, since pretty much all a program can even hope to do is cleanup as gracefully as possible and bail out. It really comes down to “where is the code that handles this condition?”. If it’s close to the code that caused it, then the whole apparatus of exceptions or pcalls() is just an ornate way of returning an error code from the callee to the caller. If it’s far away, then you WANT an exception model so that you can avoid the absurd “ripple through” model where error codes have to be returned up a winding call stack. And yes, there are some nasty examples that sit right in the middle, which is why everyone argues for hours about stuff like this :) —Tim |