public LoadController(Loader loader) { this.loader = loader; this.masterChannel = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { FMLLog.log("FMLMainChannel", Level.ERROR, exception, "Could not dispatch event: %s to %s", context.getEvent(), context.getSubscriberMethod()); } }); this.masterChannel.register(this); state = LoaderState.NOINIT; packageOwners = ArrayListMultimap.create(); }
@Test public void unhandledExceptionInEventThreadCallsSubscriberExceptionHandler() { SubscriberExceptionHandler handler = mock(SubscriberExceptionHandler.class); EventBus bus = new EventBus(handler); final IllegalStateException exception = new IllegalStateException("Excepted Unhandled Exception"); bus.register(new Object() { @Subscribe public void throwUnhandledException(TriggerUnhandledException event) { throw exception; } }); bus.post(new TriggerUnhandledException()); verify(handler).handleException(eq(exception), any(SubscriberExceptionContext.class)); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { loggers.get(context.getSubscriber().getClass()).log( Level.SEVERE, "Exception dispatching " + context.getEvent().getClass().getName() + " to " + context.getSubscriber().getClass().getName() + "#" + context.getSubscriberMethod().getName(), exception ); }
@Override public void handleException(Throwable throwable, SubscriberExceptionContext subscriberExceptionContext) { String eventName = subscriberExceptionContext.getEvent().getClass().getSimpleName(); Class<?> subscriber = subscriberExceptionContext.getSubscriber().getClass(); LogManager.getLogger(subscriber).error("An error occurred on event " + eventName + " in " + subscriber.getName(), throwable); }
@Subscribe public void buildModList(FMLLoadEvent event) { Builder<String, EventBus> eventBus = ImmutableMap.builder(); for (final ModContainer mod : loader.getModList()) { //Create mod logger, and make the EventBus logger a child of it. EventBus bus = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { LoadController.this.errorOccurred(mod, exception); } }); boolean isActive = mod.registerBus(bus, this); if (isActive) { activeModList.add(mod); modStates.put(mod.getModId(), ModState.UNLOADED); eventBus.put(mod.getModId(), bus); FMLCommonHandler.instance().addModToResourcePack(mod); } else { FMLLog.log(mod.getModId(), Level.WARN, "Mod %s has been disabled through configuration", mod.getModId()); modStates.put(mod.getModId(), ModState.UNLOADED); modStates.put(mod.getModId(), ModState.DISABLED); } modNames.put(mod.getModId(), mod.getName()); } eventChannels = eventBus.build(); }
MentorEventBus() { this(Executors.newWorkStealingPool(), new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { Log.error("Error in event handler ({})", context, exception); } }); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { String message = "Event: " + context.getEvent() + "\r\nSubscriber: " + context.getSubscriber() + "\r\nSubscriber method:" + context.getSubscriberMethod(); ErrorHandlerProvider.handle(context.getEventBus().toString(), message, exception); }
@Override public void handleException(final Throwable e, final SubscriberExceptionContext context) { if ((e instanceof ClassCastException) && e.getMessage().contains(PoisonPill.class.getName())) { LOG.debug("Poision Pill processed on: {}", context.getSubscriber().getClass().getSimpleName()); } else { String msg = String.format("Could not call %s/%s on bus %s", context.getSubscriber().getClass().getSimpleName(), context.getSubscriberMethod().getName(), name); LOG.error(msg, e); } }
@Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { String errmsg = "Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod() + "\n Event: " + context.getEvent() + "\n Bus: " + context.getEventBus(); logger.error(errmsg, exception); }
protected void onSubscriberException(Throwable exception, @Nullable SubscriberExceptionContext exceptionContext) { if (exception instanceof InterruptedException) { logger.log(Level.FINE, "EventBus Subscriber threw InterruptedException", exception); Thread.currentThread().interrupt(); } else { logger.log(Level.SEVERE, "An event subscriber threw an exception", exception); eventBus.post(new UnexpectedThrowableEvent(exception, "An event subscriber threw an " + "exception on thread '" + Thread.currentThread().getName() + "'")); } }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { Class<?> listenerClass = context.getSubscriber().getClass(); String method = context.getSubscriberMethod().getName(); String event = context.getEvent().getClass().getSimpleName(); Logger logger = LoggerFactory.getLogger(listenerClass); logger.error("Error dispatching event '" + event + "' to '" + listenerClass.getSimpleName() + "." + method + "'", exception); }
public EventBusThatPublishesUnhandledExceptionEvents() { super(new SubscriberExceptionHandler() { @Override public void handleException(Throwable throwable, SubscriberExceptionContext subscriberExceptionContext) { postUncaughtExceptionEvent(throwable); } }); errorMessageBus.register(this); }
@Subscribe public void handleException(ExceptionEvent e) { if (log.isErrorEnabled()) { final String format = "当前事件为: %s\n当前订阅者为: %s\n订阅方法为: %s\nEventBus为: %s\n"; String msg = "\n"; log.error("检测到异常 :", e.getException()); msg += "===================================\n"; msg += "异常详细信息:\n"; SubscriberExceptionContext ctx = e.getContext(); if (ctx != null) { msg += String.format(format, ctx.getEvent(), ctx.getSubscriber(), ctx.getSubscriberMethod(), ctx .getEventBus()); } else msg += "无上下文信息.\n"; if (e.getExtra() != null) { msg += String.format("附加信息为: %s \n", e.getExtra()); } else msg += "无附加信息.\n"; msg += "==================================="; log.error(msg); } }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { if (context.getEvent() instanceof ExceptionEvent) { log.error("处理错误过程中发生错误 上下文:" + context, exception); return; } ExceptionEvent event = new ExceptionEvent(exception, context); bus.post(event); }
public AppEventBus() { eventbus = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { log.error("Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod()); exception.printStackTrace(); } }); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { handleError("error in thread '" + Thread.currentThread().getName() + "' dispatching event to " + context.getSubscriber().getClass() + "." + context.getSubscriberMethod().getName(), exception); }
@Override public void handleException(Throwable thrwbl, SubscriberExceptionContext sec) { com.gmt2001.Console.err.println("Failed to dispatch event " + sec.getEvent().toString() + " to " + sec.getSubscriberMethod().toString()); com.gmt2001.Console.err.printStackTrace(thrwbl); }
@Override public void handleException(Throwable throwable, SubscriberExceptionContext subscriberExceptionContext) { throwable.printStackTrace(); }
@Override public final void handleException(final Throwable exception, final SubscriberExceptionContext context) { exception.printStackTrace(); }
private static void eventExceptionHandler(Throwable exception, SubscriberExceptionContext context) { log.warn("uncaught exception in event subscriber", exception); }
@Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { logger.error("Could not dispatch event {} to subscriber {} method [{}]", context.getEvent(), context.getSubscriber(), context.getSubscriberMethod(), exception); }
@Override protected void onSubscriberException(Throwable exception, SubscriberExceptionContext exceptionContext) { // Do not call super, we don't want the default functionality subscriberExceptions.add(new SubscriberThrowablePair(exception, exceptionContext)); }
private SubscriberThrowablePair(Throwable exception, SubscriberExceptionContext exceptionContext) { this.exception = checkNotNull(exception, "Throwable cannot be null"); this.exceptionContext = checkNotNull(exceptionContext, "SubscriberExceptionContext cannot " + "be null"); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { logger.error("Hysterix EventBus exception", exception); }
@Override public void handleException(final Throwable e, final SubscriberExceptionContext context) { LOG.error(e, "Could not call %s/%s on bus %s", context.getSubscriber().getClass().getSimpleName(), context.getSubscriberMethod().getName(), name); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { throw new TechnicalException(exception); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { logger.log(Level.SEVERE, "Failure in EventBus subscriber", exception); LoggingUtil.logToRemote(Level.SEVERE, "Failure in EventBus subscriber.", exception); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { BugReport.handleCrash(exception); }
public EventBusExceptionEvent (Throwable exception, SubscriberExceptionContext context) { this.exception = exception; this.context = context; }
public ExceptionEvent(Throwable exception, SubscriberExceptionContext context) { this(exception, context, null); }
public ExceptionEvent(Throwable exception, SubscriberExceptionContext context, Object extra) { this.exception = exception; this.context = context; this.extra = extra; }