The exception specification in Java and C ++ works very differently.
This is a very good source of information for a C ++ perspective. http://www.gotw.ca/publications/mill22.htm
The main drawback of the C ++ design was the fact that if you throw an unexpected exception, it is very likely that your program will fail (see the link for details). Therefore, the exception specification is a limitation that will be applied too late.
Grass Sutter closes the article, saying:
Moral
The structure of the Java exception specification is different, you have two types of exceptions: checked (compilation time) and runtime exception (pretty much like C ++ without an exception specification).
With checked exceptions, the compiler will force the developer to handle them, otherwise the application will not compile. This is good and useful, however, the difference between the runtime and the checked exception is not entirely clear and depends on the developer, and this can cause confusion. Also, an excluded exception is associated with a difficult decision, even with simple software idioms (for example, the Proven Exception Specification and the strategy template ).
The end result, as usual, with obscure language features, was its poor use. For example, C # developers decided to abandon them.
I think java design is better than C ++ 03 for this particular topic (and I'm a big C ++ fan) because it allows the developer to write better code in a more visual way. However, you need to spend energy (coding standard and code review) to create consistent code within your development team.
source share