ERROR_HANDLER
-
i am trying to write this code in C#.i have a problem with Err.Number how can i get error number in C#. Error number is always Zero but in VB it's show the correct Error Number !! VB.net On Error GoTo ERROR_HANDLER Dim TermID As Int32 = Convert.ToInt32(txtTermId.Text) Dim EmpNum As Int32 = Convert.ToInt32(EmployeeList.SelectedItem) objFuncs.LogIn(TermID, EmpNum, "", "") StatusBar1.Text = "You successfully logged in with Employee " & EmpNum ERROR_HANDLER: MessageBox.Show(Err.Number.ToString()) Select Case Err.Number And &HFFF Case ErrCOM_InvalidEmpPassword : MsgBox("Invalid password") Case ErrCOM_CouldNotFindEmployeeFromId : MsgBox("Could not find employee from ID") Case Else : MsgBox(Err.Description) End Select C# try { int TermID = Convert.ToInt32(txtTermId.Text); int EmpNum = Convert.ToInt32(EmployeeID.Text); objFuncs.LogIn(TermID, EmpNum, "", ""); richTextmsg.Text += "You successfully logged in with Employee " + EmpNum; } catch { MessageBox.Show(Information.Err().Number.ToString()); switch(Information.Err().Number & 4098) { case ErrCOM_EmpLoggedOnOtherTerm: MessageBox.Show("The employee is logged on to another terminal", 0, null); break; case ErrCOM_SomeoneAlreadyLoggedIn: MessageBox.Show("Someone else is already logged on to this terminal", 0, null); break; }
-
i am trying to write this code in C#.i have a problem with Err.Number how can i get error number in C#. Error number is always Zero but in VB it's show the correct Error Number !! VB.net On Error GoTo ERROR_HANDLER Dim TermID As Int32 = Convert.ToInt32(txtTermId.Text) Dim EmpNum As Int32 = Convert.ToInt32(EmployeeList.SelectedItem) objFuncs.LogIn(TermID, EmpNum, "", "") StatusBar1.Text = "You successfully logged in with Employee " & EmpNum ERROR_HANDLER: MessageBox.Show(Err.Number.ToString()) Select Case Err.Number And &HFFF Case ErrCOM_InvalidEmpPassword : MsgBox("Invalid password") Case ErrCOM_CouldNotFindEmployeeFromId : MsgBox("Could not find employee from ID") Case Else : MsgBox(Err.Description) End Select C# try { int TermID = Convert.ToInt32(txtTermId.Text); int EmpNum = Convert.ToInt32(EmployeeID.Text); objFuncs.LogIn(TermID, EmpNum, "", ""); richTextmsg.Text += "You successfully logged in with Employee " + EmpNum; } catch { MessageBox.Show(Information.Err().Number.ToString()); switch(Information.Err().Number & 4098) { case ErrCOM_EmpLoggedOnOtherTerm: MessageBox.Show("The employee is logged on to another terminal", 0, null); break; case ErrCOM_SomeoneAlreadyLoggedIn: MessageBox.Show("Someone else is already logged on to this terminal", 0, null); break; }
Get the exception object in the catch statement:
catch (Exception ex)
The exception object contains information about the exception. You can even catch only specific exceptions, or handle different exceptions separately:
try {
// some dangerous code...
} catch (FormatException ex) {
// handle format exception
} catch (Exception ex) {
// handle all other .NET exceptions
} catch {
// handle all other exceptions
}The Err object is a leftover from VB6, in VB.NET it's not much more than a wrapper around an exception object. You can use Try...Catch in VB.NET, just as in C#. --- b { font-weight: normal; }