Not sure if I am missing something obvious, but I cannot seem to get exception handling to work properly. Currently, the flow is as follows:
We have a verticle acting as a REST entry point into the system. It has a HttpServer, Router etc. This works fine. Once a request comes in, it translates it into an event bus message, and sends off the message, which will then be picked up by the appropriate verticle listening on the address.
However, we would like to deal with unchecked exceptions in a uniform way, i.e. ending the RoutingContext with a proper JSON response and error message. So in the web server verticle, we do the following:
vertx.eventBus().send("/eb/some/address", new JsonObject().put("my", "data"), reply -> {
if (reply.succeeded()) {
context.response().end("well done");
} else {
context.response().end(new MyUniformErrorResponse(reply.cause()).toString());
}
});
So clearly in both cases we can end the context properly. Now, we have a verticle listening on the address, and doing the following:
vertx.eventBus().<JsonObject>.consumer("/eb/some/address", this::handleSomeAddress).exceptionHandler(this::handleException);
private void handleSomeAddress(final Message<JsonObject> message) {
throw new IllegalStateException("o my...");
}
private void handleException(final Throwable throwable) {
// this never gets called?
}
Our issue is now this, the method registered on the exception handler never gets called. Also, the message is never replied to (would have expected the message to auto reply with a failed response), which in turn causes the error received in the web server verticle message being a normal timeout exception. I would have expected the exception handler method to be called for unchecked exceptions. Surely we should not have to wrap every consumer handler in a try-catch just to catch any unchecked exceptions.
Am I missing something? Or is there a better way to universally deal with exceptions in Vert.x 3?