user355289
user355289

Reputation: 1170

How to break on exception in my code at InteliJ

enter image description hereI'm new to Java and using InteliJ Idea community edition. I previously used Visual Studio with C#, where I could select if exception would break (and wait "as breakpoint") on my code only.

meaning I could choose to avoid seeing exceptions of 3rd party libraries, until (and only if) they affect my code.

At InteliJ Idea I could not find that option... Only "stop at all exceptions" which is mostly to verbose for me

Upvotes: 2

Views: 494

Answers (1)

Andrew
Andrew

Reputation: 49606

  1. Open "View Breakpoints". enter image description here

  2. Add "Java Exception Breakpoints".

2

  1. Find the exception you want to keep track of.

    3

  2. Apply filters

enter image description here

There is no handy option to exclude/include the whole scope (e.g. your current project scope), but you may write a class pattern to filter out individual packages (e.g. -java.* -sun.*).

You also may play with the condition for hitting a breakpoint. It has the context of an exception itself (this) and, thus, this.getStackTrace() which can be used to determine what path, origin (getStackTrace()[0]), or destination (getStackTrace()[getStackTrace().length - 1]) to reject. It's not the best solution, but, at least, an option to consider.

Upvotes: 1

Related Questions