...
This noncompliant code example attempts to catch undeclared checked exceptions thrown by Class.newInstance()
. It catches Exception
and dynamically checks whether the caught exception is an instance of the possible checked exception (carefully re-throwing all other exceptions, of course), as shown below.
...
This compliant solution uses the Constructor.newInstance()
method rather than Class.newInstance()
. The Constructor.newInstance()
method wraps any exceptions thrown from within the constructor into a checked exception called InvocationTargetException
.
...
Wiki Markup |
---|
According to the Java API \[[API 2006|AA. Bibliography#API 06]\], class {{Thread}} documentation : |
Wiki Markup \[{{Thread.stop()}}\] may be used to generate exceptions that its target thread is unprepared to handle (including checked exceptions that the thread could not possibly throw, were it not for this method). For example, the following method is behaviorally identical to Java's throw operation, but circumvents the compiler's attempts to guarantee that the calling method has declared all of the checked exceptions that it may throw.
...