...
This noncompliant code example also violates ERR13-J. Do not throw RuntimeException and . It falls under EX0 of ERR14-J. Do not catch NullPointerException, RuntimeException, Exception, or Throwable.
...
Code Block | ||
---|---|---|
| ||
public static void main(String[] args) { try { NewInstance.undeclaredThrow(new IOException("Any checked exception")); } catch (ExceptionThrowable e) { if (e instanceof IOException) { System.out.println("IOException occurred"); } else if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { //some otherforward unknownto checked exceptionhandler } } } |
...
Compliant Solution (java.lang.reflect.Constructor.newInstance()
)
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="88a1f38dcdd9cbb8-b043d4cb-496048a9-8a64b4fb-ac44ed3912d817c3fe722a53"><ac:plain-text-body><![CDATA[ | [[MITRE 2009 | AA. Bibliography#MITRE 09]] | [CWE-703 | http://cwe.mitre.org/data/definitions/703.html] "Improper Check or Handling of Exceptional Conditions" | ]]></ac:plain-text-body></ac:structured-macro> |
| CWE-248 "Uncaught Exception" |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b2623109dbe0df95-83856afe-406147c8-a9d288ca-ab8882a97ac5169f2b31d7d4"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch 08]] | Item 2: "Consider a builder when faced with many constructor parameters" | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7dabc675888e76e8-ae759b89-48c342bc-8a5aa56b-6f58fcfbdbf4bb3a5b98eaa3"><ac:plain-text-body><![CDATA[ | [[Goetz 2004b | AA. Bibliography#Goetz 04b]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="97fe4bdb79551d17-d9ed6353-4e074b50-8e7ea4f5-f4db6a2d4251a0aed266c3bb"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | Chapter 11: Exceptions | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e5c777109123d5ff-4d04c5cc-4fb740a1-9516ac32-3f5cc0d9e2b763882795e13f"><ac:plain-text-body><![CDATA[ | [[Roubtsov 2003 | AA. Bibliography#Roubtsov 03]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e3af540d3a2f6e2f-768bdb9d-424c443c-99ea84c5-d6e207ab257ad6de3500af77"><ac:plain-text-body><![CDATA[ | [[Schwarz 2004 | AA. Bibliography#Schwarz 04]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9b22b065078b308d-1d296744-4a2946a6-907a9f31-e2ea5170fa0b050e509e2cee"><ac:plain-text-body><![CDATA[ | [[Venners 2003 | AA. Bibliography#Venners 03]] | "Scalability of Checked Exceptions" | ]]></ac:plain-text-body></ac:structured-macro> |
...