Another win for exceptions

In C++, exceptions have many advantages over traditional “error return values”. They’re harder to ignore, they’re a lot more flexible, you can use them in constructors, they don’t use up your return value slot, etc etc.

I’ve just noticed another advantage. Imagine you’re doing old-style success/failure return values. Somewhere in a deep chain of calls there is a failure, which gets manually propogated up to the top level. At the top-level, you get a failure value but how do you find the original failure point? Usually by binary searching down through the code.

If you’re using exceptions, you can set the DevStudio debugger to stop at the point where an exception is thrown. This immediately shows you the failure point.

Then again, you could always just code in ocaml and use it’s timetravelling debugger! In ocaml, you run your program until you notice the failure, and then you go backwards in time to find the original failure point. Ocaml rocks.