该文件是 java.nio.channels.SocketChannel.java。JDK 7u45。摘录如下:
public static SocketChannel open(SocketAddress remote)
throws IOException
{
SocketChannel sc = open();
try {
sc.connect(remote);
} catch (Throwable x) {
try {
sc.close();
} catch (Throwable suppressed) {
x.addSuppressed(suppressed);
}
throw x;
}
assert sc.isConnected();
return sc;
}
编译器如何让该代码通过?签名声明IOException,但方法的主体捕获Throwable并追溯它。我不明白什么?