What is the best alternative “On Error Resume Next” for C#?

后端 未结 11 2788
南方客
南方客 2021-02-19 08:12

If I put empty catch blocks for my C# code, is it going to be an equivalent for VB.NET\'s \"On Error Resume Next\" statement.

try
{
    C# code;
}

catch(excepti         


        
11条回答
  •  星月不相逢
    2021-02-19 08:28

    Using "On Error Resume Next" is not a good idea for error handling (of course, this is my personal opinion, but seems that most of the developers agree with me though). As other guys advised you in previous posts, use Try...Catch...Finally (whether in VB.NET or C#).

    This is a very smart option for error handling, but it will also allow you to do nothing with the error (an empty catch block) :) I would suggest you to put every line of code (which may cause error) in separate Try...Catch Block, so that you would have the opportunity to do whatever you want if an error occurs. Happy Coding guys :)

提交回复
热议问题