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

后端 未结 11 2795
南方客
南方客 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:50

    You need to analyze the On Error Resume Next statements one by one and see what their purpose is. Some may be just sloppy code, but there are valid reasons for On Error Resume Next in Visual Basic 6.0 code.

    Some examples of why to use On Error Resume Next in Visual Basic 6.0 code:

    • To check if a given key exists in a Visual Basic 6.0 collection. The only way to do this is to access the element by key, and handle the error that is raised if the key does not exist. When converting to .NET, you can replace this by a check for the existence of the key.

    • Parsing a string to an integer. In .NET you can use TryParse.

提交回复
热议问题