|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Headache about Error Handling and DebuggingFunction foo() Try ‘ many loops and codes and nested try catch here! …… Catch (ex as Exception) Msgbox ex.message Finally … end try End function My headache is: when it causes an exception, it’s very hard for me to locate which line causes the error. I remember if I use the “On Error Goto Err_Hanlder†method, I can always use a simple “Resume†statement to help me locate the buggy line. But I heard the VB’s “On Error GoTo†is not recommended and also remember I can only use the â€try catch†in C#, C++ or Java. Question: Is there an easy method to achieve the same effect as the resume (I mean for debugging purpose)? or can I set the IDE to break at the buggy line instead of at the catch block? Is this a legitimate reason that favor “On Error Goto†more than “Try Catchâ€? Look forward your insight. James James,
In VS 2003 you can break into the debugger when an exception is thrown. From the Debug menu, choose Exceptions. From the Exceptions dialog select Common Language Runtime Exceptions. Click the radio button to break into the debugger when an exception is thrown. Now when an exception is thrown the debugger will highlight the line causing the exception, even though the code is within a Try Catch block. Kerry Moorman Show quoteHide quote "James Ma" wrote: > Now I am debugging a buggy VB.NET function like following > > Function foo() > Try > ‘ many loops and codes and nested try catch here! > …… > Catch (ex as Exception) > Msgbox ex.message > Finally > … > end try > End function > > My headache is: when it causes an exception, it’s very hard for me to locate > which line causes the error. I remember if I use the “On Error Goto > Err_Hanlder†method, I can always use a simple “Resume†statement to help me > locate the buggy line. But I heard the VB’s “On Error GoTo†is not > recommended and also remember I can only use the â€try catch†in C#, C++ or > Java. > > Question: Is there an easy method to achieve the same effect as the resume > (I mean for debugging purpose)? or can I set the IDE to break at the buggy > line instead of at the catch block? Is this a legitimate reason that favor > “On Error Goto†more than “Try Catchâ€? > > Look forward your insight. > James > Thank you so much. It's working, though I'm using VS2005.
Show quoteHide quote "Kerry Moorman" wrote: > James, > > In VS 2003 you can break into the debugger when an exception is thrown. > > From the Debug menu, choose Exceptions. From the Exceptions dialog select > Common Language Runtime Exceptions. Click the radio button to break into the > debugger when an exception is thrown. > > Now when an exception is thrown the debugger will highlight the line causing > the exception, even though the code is within a Try Catch block. > > Kerry Moorman > > > "James Ma" wrote: > > > Now I am debugging a buggy VB.NET function like following > > > > Function foo() > > Try > > ‘ many loops and codes and nested try catch here! > > …… > > Catch (ex as Exception) > > Msgbox ex.message > > Finally > > … > > end try > > End function > > > > My headache is: when it causes an exception, it’s very hard for me to locate > > which line causes the error. I remember if I use the “On Error Goto > > Err_Hanlder†method, I can always use a simple “Resume†statement to help me > > locate the buggy line. But I heard the VB’s “On Error GoTo†is not > > recommended and also remember I can only use the â€try catch†in C#, C++ or > > Java. > > > > Question: Is there an easy method to achieve the same effect as the resume > > (I mean for debugging purpose)? or can I set the IDE to break at the buggy > > line instead of at the catch block? Is this a legitimate reason that favor > > “On Error Goto†more than “Try Catchâ€? > > > > Look forward your insight. > > James > > > Now I am debugging a buggy VB.NET function like following Another alternative you can do is to add line numbers to your code and retrieve > My headache is: when it causes an exception, it's very hard for me to > locate which line causes the error. I remember if I use the "On Error > Goto Err_Hanlder" method, I can always use a simple "Resume" statement > to help me locate the buggy line. But I heard the VB's "On Error GoTo" > is not recommended and also remember I can only use the "try catch" in > C#, C++ or Java. the last successful line using the ERL() function (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/valrferlproperty.asp). This function has been in VB but undocumented between versions 3 and 6. It is now documented again. See http://devauthority.com/blogs/jwooley/archive/2005/12/21/661.aspx for a sample implementation. Jim Wooley And another alternative is, instead of displaying the exception message in a
message box, write the exception itself to the console: Console.Writeline(ex.ToString()) This will give you the stack trace which in turn will show you the name of the source file and the line number along with the procedure name. Show quoteHide quote "James Ma" <Jame***@discussions.microsoft.com> wrote in message news:AABD1846-9ADA-4256-B9C1-89593A0EC074@microsoft.com... > Now I am debugging a buggy VB.NET function like following > > Function foo() > Try > ‘ many loops and codes and nested try catch here! > …… > Catch (ex as Exception) > Msgbox ex.message > Finally > … > end try > End function > > My headache is: when it causes an exception, it’s very hard for me to > locate > which line causes the error. I remember if I use the “On Error Goto > Err_Hanlder” method, I can always use a simple “Resume” statement to help > me > locate the buggy line. But I heard the VB’s “On Error GoTo” is not > recommended and also remember I can only use the ”try catch” in C#, C++ or > Java. > > Question: Is there an easy method to achieve the same effect as the resume > (I mean for debugging purpose)? or can I set the IDE to break at the buggy > line instead of at the catch block? Is this a legitimate reason that favor > “On Error Goto” more than “Try Catch”? > > Look forward your insight. > James >
Splitting a large string variable into lines <= 70 chars
Custom size paper problem XML Commenting BindingList: How to implement Find? Links Scrolling a Datagrid with code Adding Dataview or datatables to static DataSet Saving Rich Text to a SQL Database Sending Mail via MAPI - VB .NET 2005 Obtaining complete User List |
|||||||||||||||||||||||