In java the compiler complains about uncatched exceptions.
I use exceptions in C++ and I miss that feature.
Is there a tool out there capable of doing it? maybe a compiler option (but I doubt it)
In java the compiler complains about uncatched exceptions.
I use exceptions in C++ and I miss that feature.
Is there a tool out there capable of doing it? maybe a compiler option (but I doubt it)
There really isn't any way of doing that in C++. But it's easy enough to provide default exception handling at the top level of your program which will catch anything that got missed in the lower levels. Of course, you really don't want to catch most exceptions at this level, but you can at least provide reasonable diagnostic messages.
a static analyzer can run over your code and warn you if a function might throw an unhandled exception
You just have to catch all exceptions at the top level. Typically this will be enough:
try {
//do stuff
} catch( std::exception& e ) {
// log e.what() here
} catch( YourCustomExceptionHierarchyRoot& e) {
// Perhaps you have smth like MFC::CException in your library
// log e.MethodToShowErrorText() here
} catch( ... ) {
// log "unknown exception" here
}
you will need to do this at the top level of your program (smth like main()).
Also if you implement COM methods you'll have to do the same for each COM-exposed piece of code - throwing exceptions through the COM boundary is not allowed.