Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#FFcccc
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="5ca5a832567e23da-73e23eeb-43a74d7b-aed0aba4-5717996c0a5570bbde753c07"><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="ac7d624b1ef2ce3e-84e9497c-4ced4071-8cd1926d-23aec6831d51730ea8aa8a73"><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="635106a4617c97da-88a5383e-415148d2-a82e99a1-d2e015d3e8bbcb7e495ea853"><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="f8415d903f21d4a6-055f73ee-48c24fc2-bf4796d7-2096dbf6db4dfd730b659d01"><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="a3d524e4b8f86ed1-bf78f164-45c64a91-af3cac3d-45bc75fca9b7b9e34c047f3e"><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="cfc53af3c4a243d8-1b37e159-4ae24790-94839d69-d7d2e05d8408706c5b8877b2"><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="b396d8abac975213-0ad44033-49614103-b7e7aa9e-aa29d5c77b7304413b926186"><ac:plain-text-body><![CDATA[

[[Venners 2003

AA. Bibliography#Venners 03]]

"Scalability of Checked Exceptions"

]]></ac:plain-text-body></ac:structured-macro>

...