Is it OK to try/catch something just to check if an exception was thrown or not?

前端 未结 10 655
Happy的楠姐
Happy的楠姐 2020-12-28 13:09

Is it a good way to try something useless just to see if a particular exception is thrown by this code ?
I want to do something when the exception is thrown, and nothing

10条回答
  •  爱一瞬间的悲伤
    2020-12-28 13:28

    There's nothing wrong with doing this; after all, proponents of a certain other language are fond of saying "it's easier to apologise than to ask permission", that is, it's easier to wait for something to fail and deal with it than it is to avoid failure altogether. In this case, since there is no alternative, absolutely go for it.

提交回复
热议问题