Surround with...
Hi,
I usually use the "Surround with..." (CtrlAltT) functionality with
methods that throw exception and, in case they can throw one of many
exceptions, the generated code looks like the following:
try {
method();
}
catch (FirstException ex) {
doesNotMatter();
}
catch (SecondException ex) {
doesNotMatter();
}
catch (ThirdException ex) {
doesNotMatter();
}
Sometimes, it matters the way you handle the different exceptions;
sometimes, it doesn't. So, what I'd like to suggest is a way to replace
all "catch (...Exception ex)" by only one that catches their closest
common superclass. The code would look like:
try {
method();
}
catch (Exception ex) {
doesNotMatter();
}
It could be either a refactoring item or the "Surround with..." could
have both options.
Sorry if this was already suggested. I couldn't find in the tracker.
Regards,
Franklin.
Please sign in to leave a comment.
+1
You can do this with surrounding live template.
try {
$SELECTION$
} catch (Exception e){
// my handle.
}
Exception may not be the closest common superclass.