Exceptions thrown by code excerpt


I am not very proficient in IntelliJ IDEA (YET :D ).

I have a "proficiency" related question.

Let's say I have a code excerpt that is throwing some checked (and unchecked) exceptions. And I already have some catch blocks. But inspection profile says "Exception is too broad, masking ]]>".

Now what I would like to do is:
- select the code excerpt
- run some "Exception" analysis that reports what exceptions are really thrown (the YYYY above) and by what call. Is this possible with IDEA ? So I would like to get a panel in which exceptions are grouped by type (say) and under each I get a list of locations where that exception may be thrown. This would help me A LOT.

If you know of such a setting/option, please let me know.

Thank you so much,

Comment actions Permalink

Hello Cristian,

Not exatcly what you want but try pressing CtrlShiftF7 on catch and try

Maxim Shafirov
JetBrains, Inc
"Develop with pleasure!"

Comment actions Permalink

Thank you very much Maxim.

CtrlShiftF7 is useful indeed. Never used it before.

However, I guess you understood exactly what my 'requirement' is. For example I have something like:

And I have to maintain this ...

Could IDEA address this in a future release? It would be very helpful, especially on big blocks of code (legacy systems that we need to improve )


Comment actions Permalink

You could temporarily comment out the catch block (leaving only the }
character) and then apply the quick fix "Add Catch Clause(s)" on the
errors that appear in the try block.


Comment actions Permalink

Hello Cristian,

You could select the code fragment and do a surround with try/catch (which
will create an individual catch clause for each thrown exception). Then CtrlShifF7
on each catch clause will tell you where the exception is thrown.

While (temporarily) changing your code, the above does tell you what you
need to know.


Comment actions Permalink

This is a better approach.
Thanks a lot.


Comment actions Permalink

There is nothing that does what you want. You can see if what Maxim suggested works for you or you can try the following:

If you don't have a large number of exceptions to worry about, you can simply do a search one exception at a time for any of the subclassed exceptions that are getting masked. Just select your exception, lets say MyException and do Alt-F7. Make sure "Usages" is selected and hit Find. When the find results come up, look for "unclassified usages". This should report anywhere someone does something like:

throw new MyException();

It will tell you the package and filename.

Rinse, repeat.If you have a lot of exception you need to check, this will be very time consuming, otherwise, it works pretty well.


Please sign in to leave a comment.