I'm having a discussion about which way to go in a new C++ project. I favor exceptions over return codes (for exceptional cases only) for the following reasons -
- Constructors can't give a return code
- Decouples the failure path (which should be very rare) from the logical code which is cleaner
- Faster in the non-exceptional case (no checking if/else hundreds of thousands of times)
- If someone screws up the return code settings (forgets to return FAIL) it can take a very long time to track down.
- Better information from the message contained in the error. (It was pointed out to me that a return enum could do the same for error codes)
- From Jared Par Impossible to ignore without code to specifically designed to handle it
These are the points I've come up with from thinking about it and from google searches. I must admit to being predisposed to exceptions having worked in C# for the past couple of years. Please post further reasons for using exceptions over return codes. For those who prefer return codes, I would also be willing to listen to your reasoning. Thanks