我想使用try-catch塊來處理兩種情況:特定的異常和其他異常。我可以這樣做嗎? (示例)Try-catch short-circuit/fall-through java
try{
Integer.parseInt(args[1])
}
catch (NumberFormatException e){
// Catch a number format exception and handle the argument as a string
}
catch (Exception e){
// Catch all other exceptions and do something else. In this case
// we may get an IndexOutOfBoundsException.
// We specifically don't want to handle NumberFormatException here
}
NumberFormatException是否也會由底部塊處理?
難道你只是試試嗎? – 2012-07-18 01:58:37
是的,我可以,但是這對其他人也是有用的,我希望。此外,davidbuzatto的加入也揭示了一個我不知道的特徵,所以通過這個問題我獲得了更多的信息,而不是通過一個簡單的測試。 – 2012-07-18 02:02:13