5 ms·
He is comparing checking the error status in C to notifying about an error in C++. Think about it. Those are different things. You can think about throwing exce
by 10098 13y ago
He is comparing checking the error status in C to notifying about an error in C++. Think about it. Those are different things.
You can think about throwing exceptions as returning an error status, except the code that handles the error in the caller function is isolated into the catch block.
- rumcajz 13y agoUnless there's no catch block in the caller function. Then it starts to get messy.
- 10098 13y agoTo 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.