{"record":{"id":"cd32050b80666e8e","repo":"greenrobot/EventBus","slug":"invoking-subscriber-failed","errorCode":null,"errorMessage":"Invoking subscriber failed","messagePattern":"Invoking subscriber failed","errorType":"exception","errorClass":"EventBusException","httpStatus":null,"severity":"error","filePath":"EventBus/src/org/greenrobot/eventbus/EventBus.java","lineNumber":537,"sourceCode":"            handleSubscriberException(subscription, event, e.getCause());\n        } catch (IllegalAccessException e) {\n            throw new IllegalStateException(\"Unexpected exception\", e);\n        }\n    }\n\n    private void handleSubscriberException(Subscription subscription, Object event, Throwable cause) {\n        if (event instanceof SubscriberExceptionEvent) {\n            if (logSubscriberExceptions) {\n                // Don't send another SubscriberExceptionEvent to avoid infinite event recursion, just log\n                logger.log(Level.SEVERE, \"SubscriberExceptionEvent subscriber \" + subscription.subscriber.getClass()\n                        + \" threw an exception\", cause);\n                SubscriberExceptionEvent exEvent = (SubscriberExceptionEvent) event;\n                logger.log(Level.SEVERE, \"Initial event \" + exEvent.causingEvent + \" caused exception in \"\n                        + exEvent.causingSubscriber, exEvent.throwable);\n            }\n        } else {\n            if (throwSubscriberException) {\n                throw new EventBusException(\"Invoking subscriber failed\", cause);\n            }\n            if (logSubscriberExceptions) {\n                logger.log(Level.SEVERE, \"Could not dispatch event: \" + event.getClass() + \" to subscribing class \"\n                        + subscription.subscriber.getClass(), cause);\n            }\n            if (sendSubscriberExceptionEvent) {\n                SubscriberExceptionEvent exEvent = new SubscriberExceptionEvent(this, cause, event,\n                        subscription.subscriber);\n                post(exEvent);\n            }\n        }\n    }\n\n    /** For ThreadLocal, much faster to set (and get multiple values). */\n    final static class PostingThreadState {\n        final List<Object> eventQueue = new ArrayList<>();\n        boolean isPosting;\n        boolean isMainThread;","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBus/src/org/greenrobot/eventbus/EventBus.java#L519-L555","documentation":"Thrown from handleSubscriberException when the EventBus was built with throwSubscriberException=true (EventBusBuilder.throwSubscriberException or EventBus.builder().throwSubscriberException()) and a subscriber method threw. Normally subscriber exceptions are logged and/or delivered as a SubscriberExceptionEvent to subscribers of that type; with the strict flag set, the original cause is rethrown wrapped in EventBusException('Invoking subscriber failed') so the posting thread crashes — a deliberate fail-fast mode for development.","triggerScenarios":"A @Subscribe method throwing any runtime exception (NPE, IllegalStateException, network error) while EventBus is configured with throwSubscriberException; the exception propagates out of post() on the posting thread, or out of the MAIN/BACKGROUND poster thread.","commonSituations":"Teams enabling throwSubscriberException in debug builds to surface swallowed errors; a subscriber doing I/O that intermittently fails; an exception thrown only for a specific event payload reaching production with the strict flag still enabled.","solutions":["Fix the root cause named in the wrapped cause of the EventBusException (read the full stack trace: getCause() is the subscriber's original exception)","Keep throwSubscriberException enabled only in debug builds: EventBus.builder().throwSubscriberException(BuildConfig.DEBUG).installDefaultEventBus()","For production, handle failures inside the subscriber itself, or subscribe to SubscriberExceptionEvent to centralize error handling","Ensure the failing subscriber never receives events it cannot process (narrow its event type)"],"exampleFix":"// before\nEventBus.builder().throwSubscriberException(true).installDefaultEventBus();\n// any subscriber crash kills the posting thread in production\n\n// after\nEventBus.builder()\n    .throwSubscriberException(BuildConfig.DEBUG)\n    .installDefaultEventBus();\n\n// and in code\n@Subscribe\npublic void onEvent(SubscriberExceptionEvent ex) {\n    crashReporter.log(ex.throwable); // centralized handling\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    EventBus.getDefault().post(event);\n} catch (EventBusException e) {\n    if (\"Invoking subscriber failed\".equals(e.getMessage())) {\n        Throwable subscriberError = e.getCause(); // original exception from the handler\n        errorHandler.report(subscriberError); // log/report, keep app alive\n        return;\n    }\n    throw e;\n}","preventionTips":["Enable throwSubscriberException only in debug builds via BuildConfig.DEBUG","Subscribe to SubscriberExceptionEvent for production error routing","Wrap risky work inside subscriber bodies in their own try-catch"],"tags":["eventbus","subscriber-exception","fail-fast","configuration"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}