It's a really stupid question but I was wondering something. I have a variable that I have to fill up with an Integer. In some case the source from where I'm getting the data could return an empty string or just be offline.
I do not have to handle the offline case because the program will never come this far if the source it's offline. So I thought to do something like this:
int i = 0;
try {
i = mySource.getInt();
}
finally {
System.out.println(i);
}
int i = 0 is my base value so if I have to parse the empty string I'll just use the initial value. In this case we're gonna generate an exception and it will not be catched. Is there a way to do something like this without handling the exception (so without using catch(Exception e){}) or is it just bad practice?
Just to clarify: I do not need to check if the source is online now because it's a parsed xml file so I'll check if it's offline when I'm downloading the file.
try...finallywith nocatch, no, it isn't. The main problem with checked exceptions is stupid programmers catching them when they have no way to handle them. If you can't recover, don't catch.throws Throwableon every single method?