Advancing error handling from VB6 to VB.NET


Summary
This topic shows ArcGIS developers how to take advantage of the .NET Framework best practices for error handling when advancing their custom applications from Visual Basic 6 (VB6) to Visual Basic .NET (VB .NET).

About advancing error handling from VB6 to VB .NET

In VB6, error handling is performed using the statements On Error Goto and On Error Resume Next. VB .NET continues to honor these VB6 statements for legacy purposes but a better mechanism exists for error handling. The preferred VB .NET error handling mechanism is by using Try Catch Finally and Throw Exception statements. For a valuable resource that ArcGIS developers can learn from, see How to use structured exception handling in Visual Basic .NET or in Visual Basic 2005 on the Microsoft Support Web site.
The following is a simple code example of VB6 error handling statements:
On Error GoTo ErrorHandler
 ...
 Exit Sub
ErrorHandler:
  MsgBox CStr(Err.Number) & " " & Err.Description
The following is a simple code example of VB .NET error handling statements:
[VB.NET]
Try
If x = 0 Then
    Throw New System.DivideByZeroException
End If
Catch ex As Exception
MessageBox.Show(ex.InnerException.ToString)
Finally
'Code to do any final clean up.
'This sections always executes.
End Try


See Also:

Migrating from VB6 to VB.NET
General steps for migrating from VB6 to VB.NET




Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine