H
Harold Yarmouth
Just thought I'd share these.
First, clicking a return type in a method declaration highlights all the
expressions within the method body that can cause the method to exit.
This seems to include checked exception throws, including method calls
that might throw, and returns. Useful if you want to find all the
returns to see which one is responsible for those unexpected and
troublesome nulls you've been getting, or whatever.
Stuff that can throw checked exceptions, but not any that escape the
method uncaught, doesn't get highlighted.
Second, clicking an exception class in the throws clause of a method
declaration highlights the expressions within the method body that can
throw that exception out of the method.
So if you have:
public int method () throws IOException, InterruptedException {
if (foo) {
sleep(1000);
return 0;
}
InputStream in = new FileInputStream(someFile);
try {
int bar = in.read();
if (bar == 'X') {
try {
doSomethingElseWithAnotherFile();
} catch (IOException e) {
// Ignore, will be retried later anyway.
}
}
} finally {
try {
in.close();
} catch (IOException e) {
// Ignore and let original exception propagate.
}
}
return 42;
}
clicking "int" in the method declaration will highlight the "return 0"
and "return 42" as well as the "sleep(1000)", "new
FileInputStream(someFile)", and "in.read()" expressions. Clicking
IOException will highlight the latter two. And clicking
InterruptedException will highlight the sleep.
The sole time this gets annoying is if I select a return type or
exception type in a method declaration in order to find occurrences of
that type in the file (which was how I discovered these features).
Overall, though, I find these handy. Finding all the exit points is
useful for debugging or just double-checking your logic, and finding all
the places that can throw some particular checked exception will also be
useful.
The IDE that shall not be named seemed to lack this feature the last
time I had to use it. I definitely recall actually deleting throws from
methods in it so that the IDE would highlight where the exceptions got
thrown -- by indicating an error. (Changing the return type to something
incompatible can find all your "return" statements similarly in any
auto-linting Java IDE.)
First, clicking a return type in a method declaration highlights all the
expressions within the method body that can cause the method to exit.
This seems to include checked exception throws, including method calls
that might throw, and returns. Useful if you want to find all the
returns to see which one is responsible for those unexpected and
troublesome nulls you've been getting, or whatever.
Stuff that can throw checked exceptions, but not any that escape the
method uncaught, doesn't get highlighted.
Second, clicking an exception class in the throws clause of a method
declaration highlights the expressions within the method body that can
throw that exception out of the method.
So if you have:
public int method () throws IOException, InterruptedException {
if (foo) {
sleep(1000);
return 0;
}
InputStream in = new FileInputStream(someFile);
try {
int bar = in.read();
if (bar == 'X') {
try {
doSomethingElseWithAnotherFile();
} catch (IOException e) {
// Ignore, will be retried later anyway.
}
}
} finally {
try {
in.close();
} catch (IOException e) {
// Ignore and let original exception propagate.
}
}
return 42;
}
clicking "int" in the method declaration will highlight the "return 0"
and "return 42" as well as the "sleep(1000)", "new
FileInputStream(someFile)", and "in.read()" expressions. Clicking
IOException will highlight the latter two. And clicking
InterruptedException will highlight the sleep.
The sole time this gets annoying is if I select a return type or
exception type in a method declaration in order to find occurrences of
that type in the file (which was how I discovered these features).
Overall, though, I find these handy. Finding all the exit points is
useful for debugging or just double-checking your logic, and finding all
the places that can throw some particular checked exception will also be
useful.
The IDE that shall not be named seemed to lack this feature the last
time I had to use it. I definitely recall actually deleting throws from
methods in it so that the IDE would highlight where the exceptions got
thrown -- by indicating an error. (Changing the return type to something
incompatible can find all your "return" statements similarly in any
auto-linting Java IDE.)