1

Assuming a http scheme (i.e. new URL (“http://www.google.com/”)) ,would not the IOException be thrown on myHttpURLConnection.connect() and not on myHttpURLConnection = myURL.openConection().

I mean instanceURL.openConection() doesn't seem to open a connection immediately, and if so how can there be an IOException.

Thank You in advance.

4

2 回答 2

2

当您调用 时openConnection,将为指定 URL 准备一个连接。如果openConnection由于给定的 URL 无效而无法准备连接,IOException则会抛出 an。

有关详细信息,请参阅URL API

于 2012-10-01T02:33:56.363 回答
1

IOException包装了许多异常,例如MalformedException其中之一abc://1.1.1.1:1111MalformedExceptionIOException

于 2015-10-22T22:09:18.433 回答