Java: catching specific Exceptions

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

    My proposition - catch SQLException and check code.

    try {
        getConnectionSYS(dbConfigFile, properties);
    } catch (SQLException e){
        if (e.getErrorCode()==1017){
            getConnectionUSER(dbConfigFile, properties);
        } else {
            throw e;
        }
    }
    

提交回复
热议问题