Jump to catch block for unchecked exception being thrown from a method call

     say I have the following:

try {


throw new RuntimeException();

} catch (Exception e) {

}


If I press CTRL+ ALT + F7 in the "throw" keyword IntelliJ will take me to the catch block, but what if I have something like:

try {


someObject.methodThatThrowsNPE();


} catch(NullPointerException e) {


} catch (Exception e) {

}


If I have the cursor over methodThatThrowsNPE, and I know it throws it, how can I jump to the nearest catch clause capable of catching it??

3 comments
Comment actions Permalink

Hi Jaime,

AFAIK the IDE doesn't provide such a navigation.

Denis

0
Comment actions Permalink

Maybe an action that given a determined position of the cursor allows the user to choose an Exception type to get the nearest catch available.

It could be named something like "Get nearest catch block for Exception..."  and would allow the user to choose exception. Do you look it useful?? In some code I was working yesterday with more than 5000 lines written in a procedural style it could be useful.

0
Comment actions Permalink

Well, I can say that I haven't had situations when such a feature would be useful but that's my personal experience. You can create a dedicated feature request and we'll see if the community likes it.

Denis

0

Please sign in to leave a comment.