Is it good to catch a more general type of Exception?

后端 未结 10 1717
無奈伤痛
無奈伤痛 2021-01-06 01:22

If we are to catch specific forms of IOException, or any other kind as a matter of fact, and we only try and catch a couple (and define definitive outputs for t

10条回答
  •  不知归路
    2021-01-06 01:59

    I think it is a matter of personal preference. Personally, this seems not to be a good choice. I prefer to have code that makes sense to me with the try-catch stuff. This means being as specific as possible. I would say:

    try{
        //Code Here
    }
    catch(FileNotFoundException e){
        //Code Here
    }
    

提交回复
热议问题