views:

130

answers:

2

I'm looking for such a tool to be able to check fast if I catch all the exceptions I generate myself.

Thanks!

+1  A: 

Why not simply catch all possible exceptions:

int main() {
    try {
        // your stuff
    }
    catch( ... ) {
       // your handler
    }
}
anon
maybe because that won't tell where an exception is coming from, à-la _catch early_ ?
wilhelmtell
@Wilhelm Well, I believe in *catch late*, and letting RAII take care of any intervening problems.
anon
The answer to your question is probably that Séverin has learned, through Java, to rely on the compiler to tell him whether he has handled error cases, by telling him whether he has caught/declared all suitably-defined exceptions which are declared/thrown in a given context. If so, then a top-level catch doesn't help with that, he needs either Java-style static analysis of checked exceptions, or else an education in C++ programming style.
Steve Jessop
Yes, I can do that, but it doesn't solve my problem.I didn't express myself clearly: more than only *catching* all exceptions, I would like to check that all the exceptions that I throw are managed as precisely as possible. I don't want my program to stop what it is doing to come back to a default state.To this end, I try to catch all my exception as close as possible to the place they are thrown from, to react to them in an intelligent way.A good tool helping me to be sure that I didn't let any exception unresolved would be a good partner in my quest.
Séverin
@Steve Jessop: "he needs either Java-style static analysis of checked exceptions, or else an education in C++ programming style."Exactly.
Séverin
@Severin Read Steve's comment - what you are suggesting is not the way that good C++ programs are written. You should instead catch them as far away as possible from the throw site (but no further, of course) and have the C++ RAII mechanism handle any cleanup for you. You do know what RAII is? If not, find out before going any further. And C++ is nothing, I repeat nothing, like Java.
anon
@Neil Butterworth - I know RAII, even if I'm still a bit new to it -- but before managing error cases well (that is, making my program go back to a stable default state), I would like to avoid them as much as possible. I'm not a Java developer neither. I just have an extensive project full of exceptions and I should check that they are all properly taken into account. I'm also sure that a better methodology in writing the code will help me from getting issues - but I didn't write all the code I want to check.
Séverin
@Séverin: the problem is that even in Java, checked exception handling doesn't really do what you want. Unless you define hundreds of exception classes, you get two functions that throw the same exception (or perhaps one a subclass of the other). Your function calls both functions, and declares that it throws that exception. Actually you could/should have handled one of those two failure cases there and then. The compiler thinks you meant your caller to handle it, so doesn't complain. Generally in C++ you use exceptions only for catastrophes (Runtime or Error in Java), and fail explicitly.
Steve Jessop
+1  A: 

I think you're chasing the wind here, and the comments to Neil B's answer /should/ put you on the right track.

NEVER, EVER catch an exception just for the sake of it. Only catch exceptions where you can USEFULLY handle them. (example: retrying an operation on a backup server)

Remember almost every line of C++ can throw an AV (array index, pointer dereference, divide by zero, etc), so if you the approach of catching each of these, you'll get nowhere fast. You be heading for cargo cult coding world, where every pointer is checked for NULL before use.

Roddy
Actually, you describe Undefined Behavior. That could throw, but Undefined Behavior allows other results as well including terminating at the spot.
MSalters