Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Logging error locations

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    58

    Resolved [RESOLVED] [2005] Logging error locations

    Hi,

    Is there a way to have VB return the name of the current sub/function? What I'd like to do is something like this:

    public sub MyTest()
    try
    dim test as integer = 0
    test = "oops, it's a string"
    catch ex as exception
    console.writeline ex.message & " occurred in " & <?????>
    end try
    end sub

    So the output would be:
    Conversion from string "test" to type 'Integer' is not valid occurred in MyTest

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Logging error locations

    Just do this:
    vb Code:
    1. Console.WriteLine(ex.ToString())
    and you'll get the error message and the whole stack trace. If you want to pick and choose what info you want then you can use the exception's StackTrace property to get individual stack frames. The top frame will be the current method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    58

    Re: [2005] Logging error locations

    Perfect! Thanks mate - getting exactly what I need now...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width