Java: catching specific Exceptions

后端 未结 6 1392
迷失自我
迷失自我 2021-01-07 21:17

say I have the following

try{
//something
}catch(Exception generic){
//catch all
}catch(SpecificException se){
//catch specific exception only
}
6条回答
  •  耶瑟儿~
    2021-01-07 22:23

    As a side note, the only way to have both catch blocks called is to use nested exceptions.

    try {
      try{
      //something
      }catch(SpecificException se){
      //catch specific exception only
      throw se;
      }
    }catch(Exception generic){
    //catch all
    }
    

提交回复
热议问题