【发布时间】:2017-08-23 05:43:23
【问题描述】:
以此为例:
public class TestClass {
public static void test() throws SSLHandshakeException {
throw new SSLHandshakeException("I'm a SSL Exception");
}
public static void main(String[] args) throws SSLHandshakeException {
try {
test ();
} catch (IOException ioe) {
System.out.println("I`m handling IO exception");
}
}
}
所以,我有我的测试方法,我只是抛出一个SSLHandshakeException,它是IOException 的子类型。
输出是“我正在处理 IO 异常”。
为什么会这样?我预计我的方法会抛出SSLHandshakeException。有没有规定catch 比throws 更重要?
我只是想避免使用
try {
test ();
} catch (SSLHandshakeException se) {
throw se;
} catch (IOException ioe) {
System.out.println("I`m handling IO exception");
}
因为我认为它不太可读
【问题讨论】:
标签: java exception try-catch handle throws