C# try {} catch {}

后端 未结 11 2411
既然无缘
既然无缘 2021-02-08 10:51

hi and thanks for reading. im a newbie in programming and C# and sockets programming. in my code i try and catch problems to provide fault tolarence in my app. the following:

11条回答
  •  野性不改
    2021-02-08 11:09

    IMO:

    Catching Exception would be pretty similar to having methods with parameters that are never more specific of a class than Object; Sure you can do it but is it really the best decision 9 out of 10 times?

    What you should consider doing to simplify your code some is Catch exceptions at the highest definition that is relevant.

    For instance, in java I would

    try{...}
    catch( IOException e ) {...}
    

    to catch all IO related exceptions.

    There are too many things that can throw too many different types of exceptions, you typically should avoid using the catch-all that is Exception.

提交回复
热议问题