Java: catching specific Exceptions

后端 未结 6 1353
迷失自我
迷失自我 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:22

    This does not compile with eclipse compiler:

    Unreachable catch block for IOException. It is already handled by the catch block for Exception

    So define them the other way. Only the specific one will be caught.

提交回复
热议问题