Why do some people recommend not using exception handling in C++?

Quora Feeds

Active Member
Alec Cawley

I don't think this is C++ specific. There has been a general feeling in many programming communities that Exceptions, while apparently a good idea, have in practice been responsible for a remarkable number of subtle bugs. They are see by many as a way of postponing unpleasant decisions about error handling until later - often until too late.

The ideal function/method is a black box with defined inputs, defined outputs, and defined behaviour. But the C++ Exception mechanism means that the number outputs becomes essentially infinite. Any exception can be thrown by the function, or by any function it calls, at any depth. Java tried to handle this with checked exceptions, but that didn't work out: either you got huge lists of exceptions to be handled, or people created general exceptions which effectively lost all the subtlety of error handling typed exceptions were designed to handle.

One part of the problem is that the further you get from the site of the Exception, generally speaking the less you know about how to handle it. But designers, given the option of throwing an exception, tend far too easily to take that option, passing the problem to someone with less information about how to solve it.

So it is generally just hard experience that makes people dislike Exceptions. Solve your problems when they occur, don't pass the buck to someone else.

See Questions On Quora

Continue reading...
 
Top