Bug 296947 - [call hierarchy] Find where catch blocks are for an exception
Summary: [call hierarchy] Find where catch blocks are for an exception
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P5 enhancement with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-04 13:10 EST by Wojtek Bok CLA
Modified: 2020-10-06 16:43 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wojtek Bok CLA 2009-12-04 13:10:37 EST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.18) Gecko/20081031 MultiZilla/1.8.2.0i SeaMonkey/1.1.13
Build Identifier: 3.4

I would like to be able to highlight an exception name, then search for any catch blocks for that exception.

You can get references to the exception, but that includes all references and requires a manual search to find where the exception is being caught and handled.


Reproducible: Always
Comment 1 Markus Keller CLA 2009-12-06 18:39:13 EST
Works for me in 3.4:

Open the Search dialog, enter the type name, select "Type", select "Match locations", click the link to configure, and then select 'In expressions > Catch clauses'.
Comment 2 Wojtek Bok CLA 2009-12-09 12:36:03 EST
Ok, that finds all the catch clauses. But I did not make myself clear. What I meant was any catch clauses "upstream" from the throw which is highlighted.

So that doing a search on where MyException is thrown will show the places where THAT throw is caught, ignoring any other place it is caught from a different throw.

So if MyException is thrown in multiple places and caught in multiple places, I just want where it is caught from the method I am in.
Comment 3 Deepak Azad CLA 2009-12-09 12:48:25 EST
I like the idea, 'Catch Hierarchy' like 'Call Hierarchy'.
Comment 4 Markus Keller CLA 2009-12-10 11:21:19 EST
OK, that would indeed be something like a Call Hierarchy, but ending at those places where the exception is explicitly caught. Since this needs a recursive search, it can take quite long in the general case.
Comment 5 Wojtek Bok CLA 2009-12-18 13:57:28 EST
So the search would show all the methods between the throw and the catch?

Also, if a method catches the exception, then re-throws it, could that be also shown (highlighted)? Up to where the exception is caught and handled?

I sometimes catch an exception, do some local housekeeping (close connections), then throw it again to let some other method deal with it, such as informing the user.

---------
catch(MyException ex)
{
  connection.close();
  throw ex;
}

Thanks.
Comment 6 Thomas Leplus CLA 2018-08-07 13:27:20 EDT
I would really like to have this feature too.

A cool bonus feature would be to be able to search not only for explictly thrown exceptions. I mean for be able to click on any line of code and see where for example a NullPointerException thrown from there would be caught.

Also one corner case that this feature should be aware of is exception getting lost when someone does a return in a finally block:

try {
   ...
   throw new FooException();
   ...
} finally {
   return; // the FooException is lost at this point :(
}

In this case it would be nice to include this finally block in the search results.
Comment 7 Wojtek Bok CLA 2020-10-06 16:43:59 EDT
Just to tickle this again...

If I CTRL-hover the mouse over "FileNotFoundException" in the following:
  private void saveChanges() throws FileNotFoundException, IOException

I get a popup that allows me to:
- Open Declaration
- Open Implementation

I would an addition option added:
- Go to catch

Which would track through the various method calls until the exception catch is located, including the exception super classes. Or in the case of an un-caught Runtime exception, an error message.