4 ms·
To be fair, things may also start to get messy if you forget to check the return value of a function.
by 10098 13y ago
To be fair, things may also start to get messy if you forget to check the return value of a function.
- rumcajz 13y agoAck. Bur that's something you are not supposed to do in C. Not handling an exception within the function, on the other hand, is perfectly normal, if not encouraged, in C++.
- 10098 13y agoI wouldn't say that it's encouraged, but it indeed is normal. However, one should only do it in the case when the caller function actually can't do anything to handle the error. In this case, the idea is to pass the exception further up to the caller's caller, etc. The bad part is, you have to be mindful of it when writing code, and add exception handling code in callers as necessary, however, I would argue that writing error-handling without exceptions also requires the same level of attention. I'm not saying exceptions don't have their gotchas ([1]), however, with all due respect, I don't think that your article does a good job at convincing the reader that using exceptions is a poor choice. [1] http://ptgmedia.pearsoncmg.com/images/020163371x/supplements/exception_handling_article.html http://ptgmedia.pearsoncmg.com/images/020163371x/supplements...
- nly 13y agoThat's because exceptions aren't supposed to be 'handled'. Usually you only catch an exception while you do some cleanup, maybe print some information from it, assuming you even know what you caught, then rethrow.