News for hackers. Stuff that matters.
Re:Exploding Error Codes (C++) by kevingadd on Wednesday November 10, 2010 @06:07AM (#1889892)
A better approach for this that I use in my personal applications is to combine the concept of an error code and a result into a single object that records the 'checked' state. Attempting to fetch a value from one of these result objects will throw if the result object contains an error, which handles the common case, and the less common case - forgetting to check at all - can explode violently as described here. If you want to simply discard the error code or handle it manually, you can just check the failure status of a result object and go about your merry way. It's a nice compromise and it happens to integrate nicely if you're already using futures/promises to represent work.
Re:Exploding Error Codes (C++) by gaius on Wednesday November 10, 2010 @06:17AM (#1889917)
This is what the Maybe monad is for :-)
Re:Exploding Error Codes (C++) by masklinn on Wednesday November 10, 2010 @07:00AM (#1889997)
Or the `Either` monad, or union types/ADT in general, `Maybe` is just a pretty basic application of those.