...
Some APIs may limit the permissible exceptions thrown by particular methods. In such cases, it may be necessary to catch an exception and either wrap it in a permitted exception or translate it to one of the permitted exceptions.
Code Block | ||
---|---|---|
| ||
public void myMethod() throws MyProgramException { // ... try { // Requested file does not exist // User is unable to supply the file name } catch (FileNotFoundException e) { throw new IOExceptionMyProgramException(e); } // ... } |
Alternatively, when higher level code is also unable to recover from a particular exception, the checked exception may be wrapped in an unchecked exception and rethrown.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a43c492ae0be963e-3251d9b7-48554015-9a40b682-d7f3670cfbe59249b10d92eb"><ac:plain-text-body><![CDATA[ | [[MITRE 2009 | AA. Bibliography#MITRE 09]] | [CWE-390 | http://cwe.mitre.org/data/definitions/390.html] "Detection of Error Condition Without Action" | ]]></ac:plain-text-body></ac:structured-macro> |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a2b8d510927d245f-9335680d-42004a0f-93b7b3cd-d8988324c2d892efa0d415eb"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch 08]] | Item 65: "Don't ignore exceptions" and Item 62: "Document all exceptions thrown by each method" | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c813385656bf3115-1fde0f8a-45fa43a4-94f0b1ca-074c88cae951b30bdac2a4b5"><ac:plain-text-body><![CDATA[ | [[Goetz 2006 | AA. Bibliography#Goetz 06]] | 5.4 Blocking and interruptible methods | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a2c6a7d17a04d267-9c52dd41-476844dc-80e39bea-cdc84d933b6f9a4c7bd719c6"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [Chapter 11, Exceptions | http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html] | ]]></ac:plain-text-body></ac:structured-macro> |
...