Exceptions thrown by code excerpt

All,

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,
Cristi

6 comments

Hello Cristian,

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


Maxim Shafirov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

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 )

Cristian

0

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.

Bas

0

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.

HTH,
Andrei


0

This is a better approach.
Thanks a lot.

Cristi

0

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.

0

Please sign in to leave a comment.