Why not catch general Exceptions

后端 未结 12 1670
鱼传尺愫
鱼传尺愫 2020-11-27 16:26

My VS just told me;

Warning 2 CA1031 : Microsoft.Design : Modify \'Program.Main(string[])\' to catch a more specific exception than \'Exception\' or r

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:43

    You can set up your try catch to catch multiple different behavior types and handle the exception based on the type. For most methods and properties in the framework, you can also see what exceptions they are capable of throwing. So unless you are catching an exception from an extremely small block of code, you should probably catch specific exceptions.

提交回复
热议问题