try catch - Java HttpURLConnection dying mysteriously -
i trying use java.net.httpurlconnection make simple http call , running can't explain:
public string makegetcall(httpurlconnection con) { try { system.out.println("about make request..."); if(con == null) system.out.println("con null"); else { system.out.println("con not null"); if(con.getinputstream() == null) system.out.println("con's input stream null"); else system.out.println("con's input stream not null"); } } catch(throwable t) { system.out.println("error: " + t.getmessage()); } system.out.println("returning...") return "dummy data"; } when run this, following console output:
about make request... con not null and program terminates, without error. no exceptions thrown, doesn't exit unexpectedly, , doesn't hang or timeout...it dies.
it seems dying when check con.getinputstream() being null or not. still doesn't explain why dies quietly without indication of error. ideas? i''m willing admit have created httpurlconnection incorrectly, still, there should more indication of killing program...thanks in advance!
it seems dying when check
con.getinputstream()being null or not.
well find hard believe.
on face of it:
testing reference see if
nullcannot terminate programthe
con.getinputstream()can either throw exception or returnif return shouldn't return
null... 'cos api doesn't allow ... , see messageif exception thrown see
error: ...message
my conclusion either different thread causing application exit, or application not exiting @ all.
the other explanation can think of edit / compile / deploy / run procedure not working, , code being run doesn't match code showing use.
i suggest attempt create sscce other people can reproduce , figure out happening.
Comments
Post a Comment