Should catch blocks be used for writing logic i.e. handle flow control etc? Or just for throwing exceptions? Does it effect efficiency or maintainability of code?
What are the side effects (if there are any) of writing logic in catch block?
EDIT:
I have seen a Java SDK class in which they have written logic inside the catch block. For example (snippet taken from java.lang.Integer
class):
try {
result = Integer.valueOf(nm.substring(index), radix);
result = negative ? new Integer(-result.intValue()) : result;
} catch (NumberFormatException e) {
String constant = negative ? new String("-" + nm.substring(index))
: nm.substring(index);
result = Integer.valueOf(constant, radix);
}
EDIT2:
I was going through a tutorial where they count it as an advantage of writing logic of exceptional cases inside the exceptions:
Exceptions enable you to write the main flow of your code and to deal with the exceptional cases elsewhere.
Any specific guidelines when to write logic in catch block and when not to?