On Error Resume Next in C#

Syed Aslam Basha here from the Information Security Tools Team.

We have “On Error Resume Next” feature in VB.NET, which simply means during execution if error occurs with the current code step just go to next code step by passing the error.

As such there is no “On Error Resume Next” in C#, but we can achieve the same using try catch statements tactically as ;

  1: try
  2: {
  3:     File.Delete(FileNameWithPath);
  4: }
  5:  
  6: catch()
  7: {
  8: // do nothing
  9: }

A difference is still that in C# this works only for a single statement. You would need to repeat the block for each statement.

However, it is not a good practice.

-Syed Aslam Basha ( syedab@microsoft.com )

Microsoft Information Security Tools (IST) Team

Test Lead

---------------------------------------------------------

Please leave a comment if the blog post has helped you.