HttpClient exceptionHandler exception is always null

273 views
Skip to first unread message

Niraj Chauhan

unread,
Apr 9, 2017, 1:22:37 AM4/9/17
to vert.x

I am trying to handle exception in exceptionHandler of HttpClient. Here is my code:

HttpEndpoint.getClient(serviceDiscovery, new JsonObject().put("name","tweets"), endPoint -> {
   
if(endPoint.failed()){
        log
.error("Failed getting discovery", endPoint.cause());
   
}else{
       
HttpClient client = endPoint.result();
        client
.get("/v1/api/tweets", response -> {
            response
.bodyHandler(body -> routingContext.response().end(body.toString()));
       
})
               
.setTimeout(2000)
               
.exceptionHandler(e -> {
                    log
.error("Exception: " + e.getCause());
                    routingContext
.response().end("Error");
               
})
               
.end();
   
}
});


Here is the log output:
Apr 09, 2017 10:51:01 AM com.tweets.Routes
SEVERE
: Exception: null

I have stopped the end service to get the exception.

Tim Fox

unread,
Apr 9, 2017, 5:45:03 AM4/9/17
to vert.x
You are logging the cause of the exception not the exception itself, the exception itself is not null otherwise you would have got a NPE.

Not all exceptions have non null causes.
Message has been deleted

Thomas SEGISMONT

unread,
Apr 10, 2017, 12:32:56 PM4/10/17
to ve...@googlegroups.com
You get a NPE because e.getCause is null...

Change your code to log.error("Exception", e);

2017-04-09 12:51 GMT+02:00 Niraj Chauhan <nirajm...@gmail.com>:
The exception itself is null, when I changed my code to

log
.error("Exception: " + e.getCause().getMessage());

I got NPE(Routes.java:63 is the log.error).

Apr 09, 2017 4:18:16 PM io.vertx.core.impl.ContextImpl
SEVERE
: Unhandled exception
java
.lang.NullPointerException
    at com
.tweets.Routes.lambda$null$5(Routes.java:63)
    at io
.vertx.core.http.impl.HttpClientRequestBase.handleException(HttpClientRequestBase.java:136)
    at io
.vertx.core.http.impl.HttpClientRequestImpl.handleException(HttpClientRequestImpl.java:51)
    at io
.vertx.core.http.impl.HttpClientRequestImpl$2.handleFailure(HttpClientRequestImpl.java:707)
    at io
.vertx.core.http.impl.ConnectionManager$ConnQueue.lambda$connectionFailed$3(ConnectionManager.java:368)
    at io
.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:335)
    at io
.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:193)
    at io
.vertx.core.http.impl.ConnectionManager$ConnQueue.connectionFailed(ConnectionManager.java:362)
    at io
.vertx.core.http.impl.ConnectionManager$ConnQueue.access$1900(ConnectionManager.java:194)
    at io
.vertx.core.http.impl.ConnectionManager$ChannelConnector.lambda$connect$2(ConnectionManager.java:528)
    at io
.vertx.core.net.impl.ChannelProvider.lambda$connect$0(ChannelProvider.java:42)
    at io
.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:507)
    at io
.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:500)
    at io
.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:479)
    at io
.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:420)
    at io
.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:122)
    at io
.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:327)
    at io
.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:343)
    at io
.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:630)
    at io
.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:565)
    at io
.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:479)
    at io
.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441)
    at io
.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    at java
.lang.Thread.run(Thread.java:745)

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/02b318a2-302e-4c1f-ad53-939679e571dd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Niraj Chauhan

unread,
Apr 11, 2017, 1:28:26 AM4/11/17
to vert.x
Thanks, it worked now :)
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages