About error handling in vb.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    About error handling in vb.net

    Hi All :

    I have some question about error handling :

    Can I get some system varabile which can get current function name , also if
    error occur, can I get some system varabile which show the error line
    number ?

    For example :

    Function myFunction() as integer
    5 try
    6 a = sys.opening
    7 catch (ex as excpeption)
    8 debug.writeline system.function name ' return a string type and
    value is "myFunction "
    9 debug.writeline system.errorlin e ' return a integer type and value
    is "6"
    10 end catch
    End Function


    Thanks


  • Herfried K. Wagner [MVP]

    #2
    Re: About error handling in vb.net

    "Tom" <pclan@tomgroup .com> schrieb:[color=blue]
    > Can I get some system varabile which can get current function name , also
    > if
    > error occur, can I get some system varabile which show the error line
    > number ?[/color]

    Line numbers: If you used line numbers, you can determine the line number
    using 'Err.Erl'.

    Method name: 'System.Reflect ion.MethodBase. GetCurrentMetho d().Name'.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Tom

      #3
      Re: About error handling in vb.net

      But it seem apply for private function
      it return Run-time exception thrown : System.Argument Exception - Cannot
      evaluate a security function
      also Err.erl is 0.

      Also can I also get current class / current module name ?

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> ???
      news:uST$HchUFH A.1152@tk2msftn gp13.phx.gbl ???...[color=blue]
      > "Tom" <pclan@tomgroup .com> schrieb:[color=green]
      > > Can I get some system varabile which can get current function name ,[/color][/color]
      also[color=blue][color=green]
      > > if
      > > error occur, can I get some system varabile which show the error line
      > > number ?[/color]
      >
      > Line numbers: If you used line numbers, you can determine the line number
      > using 'Err.Erl'.
      >
      > Method name: 'System.Reflect ion.MethodBase. GetCurrentMetho d().Name'.
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>
      >[/color]


      Comment

      • Chris Dunaway

        #4
        Re: About error handling in vb.net

        Try printing out the stack trace of the exception. Maybe that will
        have the data you need.

        Comment

        • Phill.  W

          #5
          Re: About error handling in vb.net

          "Tom" <pclan@tomgroup .com> wrote in message
          news:ugkCscgUFH A.3280@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Can I get some system varabile which can get current function
          > name? also if error occur, can I get some system varabile
          > which show the error line number ?[/color]

          Yes.

          For function name (outside of an Exception Handler), use
          [System.Reflecti on.MethodBase].GetCurrentMeth od.Name()

          For Line numbers in an Exception Handler, examine the Stack
          Trace of the Exception you caught, but /only/ if your program
          (or whatever) was built in Debug Mode. When you rebuild in
          Release Mode, the line numbers no longer appear.

          Function myFunction() as integer
          Dim a As ...
          Try
          a = sys.opening
          Catch (ex as Exception)
          MessageBox.Show ( ex.ToString() )
          End Catch
          End Function

          HTH,
          Phill W.


          Comment

          Working...