C# Equivalent to VB6 Error Handling





























C# Equivalent to VB6 Error Handling

VB.NET allows VB6-style error handling for compatibility purposes.  Some elements of VB6 error handling can be converted to try/catch blocks.  Items that cannot be converted and must be addressed via refactoring are: On Error Resume Next, Resume, Resume Next, On Error GoTo -1, and references to the Err object.

 

For the simplest case, the conversion is trivial:

VB (with VB6 error handling):

Public Sub ErrorHandlingExample()
On Error GoTo ErrorHandler
'... <main logic>
ErrorHandler:
'... <error handling code>
End Sub

 

C#:

public void ErrorHandlingExample()
{
try
{
// On Error GoTo ErrorHandler
//... <main logic>
}

catch
{
//... <error handling code>
}
}

 

If you need to convert between VB.NET and C# and you are depending on the results being reliable and accurate, then you will want to have Instant C#, the best VB.NET to C# converter, or Instant VB, the best C# to VB.NET converter, at your fingertips.

 

 
 
Email your questions and comments to:  info@tangiblesoftwaresolutions.com

[Site Map]        [Home]


Copyright © 1997 - 2009 Tangible Software Solutions Inc.