Bug 414133 - Suspend on uncaught exceptions does not work in JUnit tests
Summary: Suspend on uncaught exceptions does not work in JUnit tests
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: readme
Depends on:
Blocks:
 
Reported: 2013-07-31 09:19 EDT by Marcin Wisnicki CLA
Modified: 2013-08-01 11:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcin Wisnicki CLA 2013-07-31 09:19:27 EDT
Quite simply it does not work.

Given:

@Test public void foo() { throw new RuntimeException(); }

and Java\Debug\"Suspend execution on uncaught exceptions" enabled.

invoking "Debug as JUnit test" does not result in suspension.

User breakpoints still suspend as expected, so do uncaught exceptions in java applications.
Comment 1 Michael Rennie CLA 2013-07-31 13:40:43 EDT
This is working as designed, the JUnit framework is catching the exception, so it is not 'uncaught'. To confirm add an exception breakpoint for type RuntimeException, set it only to 'caught locations', debug your snippet and the debugger will suspend in the foo() method.
Comment 2 Marcin Wisnicki CLA 2013-07-31 13:50:36 EDT
But this is useless behaviour. How am I supposed to debug JUnit tests if eclipse is not capable of easily catching exceptions. By manually tweaking breakpoint settings every time I want to catch some error or maybe single stepping through my code ? This is soooo much worse than in other IDEs.

If it's not a bug of implementation then it's a bug of design. Eclipse should aspire to be at least as good as its competition.
Comment 3 Michael Rennie CLA 2013-07-31 14:29:18 EDT
(In reply to comment #2)
> But this is useless behaviour. 

Its not, because as I mentioned, the exception is not uncaught, and to debug exceptions in JUnit tests you can simply use exception breakpoints for caught locations / exception types.
Comment 4 Marcin Wisnicki CLA 2013-07-31 15:44:26 EDT
Do you mean that I have to customize breakpoint settings every time I want to debug failing unit test ? As opposed to just pressing "Debug" button and reasonably expecting for things to "just work" ?

Can I refile it as an enhancement request ?

Do you know if Eclipse's Java debugging is extensible enough to implement custom breakpoint filtering as a plugin ?
Comment 5 Michael Rennie CLA 2013-08-01 11:27:09 EDT
(In reply to comment #4)
> Do you mean that I have to customize breakpoint settings every time I want
> to debug failing unit test ? As opposed to just pressing "Debug" button and
> reasonably expecting for things to "just work" ?
> 

No, you could configure your exception breakpoints once and they will be reused.

> Can I refile it as an enhancement request ?

You could, but in this case - stopping at thrown / caught exceptions automatically - we lean on the VM to tell us when this happens. More specifically we register an exception request and the VM will tell us that an exception has been thrown and if it is caught or not. For some light reading: http://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/request/ExceptionRequest.html

So in the JUnit case the VM says the exception is caught, and we are notified of this, so we don't suspend automatically.


> 
> Do you know if Eclipse's Java debugging is extensible enough to implement
> custom breakpoint filtering as a plugin ?

It is not (sorry). 

If you are interested in how the Java breakpoints work (filtering / etc.) have a look at org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint (and its sub-classes).