-
Enhancement
-
Resolution: Rejected
-
P4
-
None
-
7
-
generic
-
generic
In 6964607 a customer suggests that initializers should be guaranteed to complete normally (rather than throwing an exception). While the JLS only requires that an initializer *can* complete normally, it's good practice to *always* complete normally -- the non-obvious effect of an initializer throwing an exception is to possibly cut short the evaluation of constructor code, field initialization, or other initializers.
It would be reasonable to introduce a lint warning that reports a problem whenever an initializer (static or instance) contains a throw statement. One compication is that the programmer may be safely catching the exception within the initializer -- a more complete analysis would look for thrown types are not caught.
It would be reasonable to introduce a lint warning that reports a problem whenever an initializer (static or instance) contains a throw statement. One compication is that the programmer may be safely catching the exception within the initializer -- a more complete analysis would look for thrown types are not caught.
- relates to
-
JDK-6964607 missing error: initializer must be able to complete normally
-
- Closed
-