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. Visual Basic
  4. Name of offending code

Name of offending code

Scheduled Pinned Locked Moved Visual Basic
helpquestion
7 Posts 4 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.
  • J Offline
    J Offline
    Johan Hakkesteegt
    wrote on last edited by
    #1

    Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like: Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub This Err.TargetSite.Name is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. Johan

    My advice is free, and you may get what you paid for.

    C S L 3 Replies Last reply
    0
    • J Johan Hakkesteegt

      Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like: Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub This Err.TargetSite.Name is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. Johan

      My advice is free, and you may get what you paid for.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Yes, you can get the stack trace from the exception object and print it, it will tell you what method threw the exception, and a call stack down from there.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      J 1 Reply Last reply
      0
      • J Johan Hakkesteegt

        Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like: Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub This Err.TargetSite.Name is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. Johan

        My advice is free, and you may get what you paid for.

        S Offline
        S Offline
        Steven J Jowett
        wrote on last edited by
        #3

        I believe you need to check the StackTrace property. err.StackTrace

        Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

        J 1 Reply Last reply
        0
        • J Johan Hakkesteegt

          Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like: Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub This Err.TargetSite.Name is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. Johan

          My advice is free, and you may get what you paid for.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, rather than using Exception.Message and/or Exception.StackTrace you really should use Exception.ToString() it will show you at least the Message and the StackTrace but also: - additional information (e.g. the filepath on a File Not Found) - information about "inner exceptions" :)

          Luc Pattyn


          try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


          J 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, rather than using Exception.Message and/or Exception.StackTrace you really should use Exception.ToString() it will show you at least the Message and the StackTrace but also: - additional information (e.g. the filepath on a File Not Found) - information about "inner exceptions" :)

            Luc Pattyn


            try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


            J Offline
            J Offline
            Johan Hakkesteegt
            wrote on last edited by
            #5

            Thanks Luc, I'll definitely give this a try.

            My advice is free, and you may get what you paid for.

            1 Reply Last reply
            0
            • S Steven J Jowett

              I believe you need to check the StackTrace property. err.StackTrace

              Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

              J Offline
              J Offline
              Johan Hakkesteegt
              wrote on last edited by
              #6

              Thanks Steve, I will try this.

              My advice is free, and you may get what you paid for.

              1 Reply Last reply
              0
              • C Christian Graus

                Yes, you can get the stack trace from the exception object and print it, it will tell you what method threw the exception, and a call stack down from there.

                Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                J Offline
                J Offline
                Johan Hakkesteegt
                wrote on last edited by
                #7

                Thanks Christian, Steve also suggested this, and according to Luc I can get even more information out of an exception by simply using Exception.ToString(). Thank all you guys, this really helps.

                My advice is free, and you may get what you paid for.

                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