1)通常做法。子类在前,父类在后
try {
...
} catch (NumberFormatException e) {
} catch (Exception e) {
}
2)用instanceof关键字做判断
try {
...
} catch (Exception e) {
if(e instanceof NumberFormatException) {
...
}
}
既然有了以上两种方法,就不要再想着用下面这样笨拙的方法了
try {
...
} catch (Exception e) {
if("java.lang.NumberFormatException".equals(e.getClass().getName()) {
...
}
}