Why C++ Exceptions are Evils
C++ Exceptions are evils because in real life, every one wants to throw an exception upon any minor error condition. But no one bothers to write any try/catch code.
Check many of the sample code Paul M., Philips, Paul W. et al posted. None of them ever bothered to put in a try/catch.
In principle, any of the STL functions they can, even something as innocent as cout << "Hello!", could potentially fail UNEXPECTEDLY, and hence such calls need to be wrapped in try/catch. In practice, no one bother to do that.
C++ are evils also because of the ambiguity on who should catch the exception and what kind of exception could be thrown. By simply writting:
Code:
SomeClass* pObj = new SomeClass();
There are any where from a few to a few hundred possible types of exception object potentially getting thrown out, depending on the complexity of the class. The catcher has no idea what they are and can't use them to help find where the problem is, unless the caller of new SomeClass() is totally familiar with every inner functions that could potentially be called within the "new" operation.