Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ERROR_HANDLER

ERROR_HANDLER

Scheduled Pinned Locked Moved C#
csharphelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bedevian
    wrote on last edited by
    #1

    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; }

    G 1 Reply Last reply
    0
    • B Bedevian

      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; }

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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; }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups