2

I'm developing an android application, and I'm using guava eventbus. I get ambiguous errors about not being able to dispatch events. How can I investigate such problems ? and how can I get more information about the exception ?

this is a sample exception message :

04-12 20:46:35.829   9971-11208/xxx.android.init E/default﹕ Could not dispatch event: xxx.android.presentation.control.MainActivity@21139768 to public void xxx.android.presentation.control.MainActivity.showToast(xxx.core.event.EventShowToast)

ps: I replaced our company class path prefix with xxx.

James Parsons
  • 6,097
  • 12
  • 68
  • 108

1 Answers1

2

This happens if a subscriber throws an exception.

You can replace the default logger with your own, by providing an implementation of com.google.common.eventbus.SubscriberExceptionHandler to your EventBus during construction.

For example:

import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;

class CustomExceptionHandler implements SubscriberExceptionHandler {
    @Override
    public void handleException(Throwable exception, SubscriberExceptionContext context) {
        System.out.println("Handler '"+context.getSubscriber()+"' could not handle '"+context.getEvent().getClass().getName()+"'["+context.getEvent()+"]: " + exception.getMessage());
    }
}

And use it like this

EventBus eventBus = new EventBus(new CustomExceptionHandler());