I have this code:
HttpPut put = new HttpPut(url);
try {
put.setEntity(new StringEntity(body, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
// That would really not be good
e1.printStackTrace();
}
On a platform that is known to support that encoding.
The exception is never going to be raised. I will never do anything about it.
The fact that the code is there still suggests that there is a chance that it may happen, and that the rest of the code could be executed in an unreliable state. But it will never. Or if it does, graceful network connections fallback is the last of my problems.
So I have this ugly useless try catch block. What should I do with it?
(In this specific case, there is not much other choice if I want to use StringEntity
. String.getBytes
for example has a bunch of methods that would accept a Charset
object, for instance, avoiding the need to catch the exception, but not StringEntity
)