1. In VB6 you may catch err as:
    Private Sub DivideByZero()
    On Error GoTo Err_Handler
        Dim num As Integer
        Dim zero As Integer
       
        num = 100 / zero
       
    Exit_Eop:
        Exit Sub
    Err_Handler:
        MsgBox ("Error Code : " & Err.number & vbCrLf & "Error Message : " & Err.Description)
    End Sub

    In C# the equivalent would be:
    using System.Reflection;
    private void DivideByZero()
    {
     try
     {
      int zero = 0;
      int num = 100 / zero;
     }
     catch (Exception ex)
     {
      Type type = typeof(Exception);
      int errNo =  (int)type.InvokeMember("HResult", System.Reflection.BindingFlags.DeclaredOnly   | BindingFlags.NonPublic | BindingFlags.Instance |  BindingFlags.GetProperty, null, ex, null);
      string errMsg =String.Format ("Error Code : {0}\r\nError Message : {1}",errNo, ex.Message);
      MessageBox.Show(errMsg);
     }
    }
    Please note that the error code in C# would not match with what you get in VB6.


    Thanks to : Willy Denoyette
    at: http://www.techtalkz.com/c-c-sharp/121497-get-error-number-2.html
    2

    View comments

Blog Archive
Topics
Topics
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.