* Tests that the {@link UncaughtExceptionHandler} gets called correctly when
* events are fired from a subinterface of {@link EventTarget}.
*/
public void testUncaughtException() {
// Create a button with an event handler that will throw an exception.
Document doc = Browser.getDocument();
ButtonElement btn = doc.createButtonElement();
doc.getBody().appendChild(btn);
btn.addEventListener(Event.CLICK, new EventListener() {
@Override
public void handleEvent(Event evt) {
throw new RuntimeException("w00t!");
}
}, false);
// Setup the UncaughtExceptionHandler.
final Throwable[] ex = new Throwable[1];
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void onUncaughtException(Throwable e) {
ex[0] = e;
}
});
// Click it and make sure the exception got caught.
TestUtils.click(btn);
assertNotNull(ex[0]);
assertEquals("w00t!", ex[0].getMessage());
// Clean up.
GWT.setUncaughtExceptionHandler(null);
doc.getBody().removeChild(btn);
}