how can I see in intellij where exception is thrown?

已回答

how can I see in intellij where an exception is thrown? Like in this example, which code line(s) do actually throw the IOException?


private void writeObject(java.io.ObjectOutputStream s)
        throws IOException
    {
    Iterator<Map.Entry<K,V>> i =
        (size > 0) ? entrySet0().iterator() : null;

    // Write out the threshold, loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out number of buckets
    s.writeInt(table.length);

    // Write out size (number of Mappings)
    s.writeInt(size);

        // Write out keys and values (alternating)
    if (i != null) {
        while (i.hasNext()) {
        Map.Entry<K,V> e = i.next();
        s.writeObject(e.getKey());
        s.writeObject(e.getValue());
        }
        }
    }

3

Hi Tilman,

You can comment 'throws' declaration and IDEA automatically hightlights problem places.

Regards, Denis.

1

ok, that's what I feared...well, that's one of the few things that eclipse handles nicer...but still..response time to forum questions is unmatched in the business

0

Place the caret at throws keyword and press Ctrl+Shift+F7.
Or if you want eclipse-style highlighting (always automatically highhlight usages) then go to Settings | Editor and mark check box 'Highlight usages of element at caret'.

1

trigger ctrl++shift+f7 on "throws" (or on "catch" when try catch)

1

trossmy wrote:
ok, that's what I feared...well, that's one of the few things that eclipse handles nicer...but still..response time to forum questions is unmatched in the business:)

Checked IDEA facilities one more time and found that you can manage to get desired result in more convenient way - put caret on 'throws' keyword and press 'Ctrl + Shift + F7' ('highlight usages').

0

ok, that's much better...still my colleague that is a freshly converted ex eclipse user, is only partially satisfied...
thx
Tilman

0

trossmy wrote:

ok, that's much better...still my colleague that is a freshly converted ex eclipse user, is only partially satisfied...
thx
Tilman


Any concrete reasons for that over than habit to use another IDE?

0

As an intellij evangelist I hate to admit that I find the eclipse way, where you just put the caret at the exception in the throws declaration and then see where it is thrown,
much easier (and much more intuitive) then putting the caret at the throws keyword and then after pressing ctrl+shift+F7 having to choose which exception I want to see...
(see attached eclipse screenshots)



Attachment(s):
eclipse2.png
eclipse1.png
4

see reply above:

Or if you want eclipse-style highlighting (always automatically highhlight usages) then go to Settings | Editor and mark check box 'Highlight usages of element at caret'.
0

Got the point but there is a field to discuss

Current IDEA behavior with enabled auto-highlighting it to show all exception usages within the current class:

idea-highlight-exception.png
(all listed exceptions are highlighted within the method body when caret is on 'throws': )

idea-highlight-exception2.png
Both features are useful and I can't say that one of them has more value than another.

That may be the case to add a setting that allows to toogle behavior to use - feel free to submit corresponding ticket to IDEA tracker, will check community feedback.

0

well I myself am satisfied with that ctrl+shift+F7 thing (having executed the rather primitive commenting suggested above for years ... and with switched on highlighting (+testcoverage +inspections, which are a must) the editor looks too much like a candystore for my taste anyway)

0

I see, well, creating an issue may help ;-)

0

This is very nice, thank you.
Beyond that, would be nice to have a tree-structured list of such throwing points of current opened method.
About what is currently available as of 2020.2, only listed throw's are taken into the highlight. Meaning that if the throwing point is beneith a method call that throws a more general exception (such as Exception) it will not be highlighted, if you put your caret over a more specific exception, even though there can be an exception of that type being thrown.

0

How is it that IntelliJ IDEA has data flow analysis for other types yet it can't show me all the places where the exception is thrown from? Seems like it ought to be able to do this, at least for checked exceptions.

0

请先登录再写评论。