Exceptional Origins

I’ve just noticed something rather nice in Eclipse. The “Mark Occurrences” feature (Mark Occurrences) will show you where an exception is thrown. For example, here I’ve clicked on the IOEXception in the method definition.

Eclipse highlights where exceptions are thrown

You can clearly see that read(), write(), flush() and close() are points at which the IOEXception can be thrown.

Similarly, you can highlight the return type of a method to see all the exit points of a method.

Eclipse highlights all return sites in a method

One final tip about Mark Occurrences: You can optionally select occurrences in the “Next / Previous” toolbar buttons. i.e.

Enabling “next occurrence” in eclipse

Doing this allows the Next key (Command-. on my Mac, likely Ctrl-. on Windows) to jump between occurrences. So you can click on a method name and cycle through all mentions of that method in a file. Very handy. You’ll notice that it works for compile errors too.

I have to confess that I used to find Mark Occurrences quite irritating. Now I know what it can do for me, I’m a much happier punter.