How to manage uncaugth exceptions in Vaadin

Hi everyone …

We have tested the method suggested in the book of vaadin, (use to work in vaadin 6) but not in vaadin 7 . This is the source code that we have use in our MainApplication class which extends the new UI (here main is a VerticalLayout )

    final Button button = new Button("Click Me to generate an exception!",
    		new Button.ClickListener() {
    	public void buttonClick(ClickEvent event) {
    	((String)null).length(); // Null-pointer exception
    	}
    	});

// // Configure the error handler for the UI
getCurrent().setErrorHandler(new DefaultErrorHandler() {
@Override
public void error(com.vaadin.server.ErrorEvent event) {
// Find the final cause
String cause = “error fallo por que:
”;
for (Throwable t = event.getThrowable(); t != null;
t = t.getCause())
if (t.getCause() == null) // We’re at final cause
cause += t.getClass().getName() + “
”;
// Display the error message in a custom fashion
main.addComponent(new Label(cause, ContentMode.HTML));
// Do the default error handling (optional)
doDefault(event);
}
});
main.addComponent(button);
setContent(main);

How do we manage this uncaugth exceptions in vaadin 7 now ? any suggestion, documentaion or URL explaining the new technique in Vaadin ?

Regards,

Pedro

We do it with an Session init Listener and it works.

You have to register this session listener to the Vaadin Service - we do this in our own Servlet that extendes VaadinServlet and override the createServletService where we add the listener shown below.

basicly this (ignore the Spring annotations):


@Component
class CongfigSessionInitListener implements SessionInitListener {

  /** Serial version uid. */
  private static final long serialVersionUID = -4030237252457675312L;

  @Inject
  private ErrorHandler errorHandler;
  @Inject
  private ConverterFactory converterFactory;

  @Override
  public void sessionInit(SessionInitEvent event) throws ServiceException {
    VaadinSession session = event.getSession();
    session.setConverterFactory(converterFactory);
    session.setErrorHandler(errorHandler);
  }

}

ok… but where do you define these variables ?: they look injected in your source code by spring (in my case would be Autowired by spring) but still where are they are defined, could you publish your source code for these components ?

  private ErrorHandler errorHandler;
 
  private ConverterFactory converterFactory;

Thanks for your quick reply … this practica (fix) would be included in the vaadin book …

Regards

Pedro

Renier or Vaadin team

Coudl you provide us the code of these classes, part of your previous example … or an alternate technique to manage these exceptions …? (as we mentioned in our previous post the current method included in the vaadin book doesn´t work in vaadin 7)

private ErrorHandler errorHandler;

private ConverterFactory converterFactory

Regards,

Pedro[

I have a similar problem, i need this solution, thank you very much

For my app prototype (Vaadin 7.1) it works this way (I removed Spring integration from this code, hope I didn’t make syntactic mistakes, though you should be able to understand the idea, which is the same as Rainer already posted…).


public class MyApplicationServlet extends VaadinServlet {
	
    @Override
    protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
		VaadinServletService service = new VaadinServletService(this, deploymentConfiguration) {
			@Override
			public void requestStart(VaadinRequest request, VaadinResponse response) {
				super.requestStart(request, response);
			}

			@Override
			public void requestEnd(VaadinRequest request, VaadinResponse response, VaadinSession session) {
				super.requestEnd(request, response, session);
			}
		};      
		
		service.init();

        service.addSessionInitListener(new SessionInitListener() {
            @Override
            public void sessionInit(SessionInitEvent event) throws ServiceException {
                VaadinSession session = event.getSession();
				session.setErrorHandler(getDefaultErrorHandler()); //Automatic exception handling.
            }
        });

        return service;
    }
    
	
}