How to deal with checked exceptions that cannot ever be thrown
Posted
by
ammoQ
on Programmers
See other posts from Programmers
or by ammoQ
Published on 2011-11-29T09:17:45Z
Indexed on
2011/11/29
10:07 UTC
Read the original article
Hit count: 238
java
|exception-handling
Example:
foobar = new InputStreamReader(p.getInputStream(), "ISO-8859-1");
Since the encoding is hardcoded and correct, the constructor will never throw the UnsupportedEncodingException declared in the specification (unless the java implementation is broken, in which case I'm lost anyway). Anyway, Java forces me to deal with that exception anyway.
Currently, it looks like that
try {
foobar = new InputStreamReader(p.getInputStream(), "ISO-8859-1");
}
catch(UnsupportedEncodingException e) { /* won't ever happen */ }
Any ideas how to make it better?
© Programmers or respective owner