Break on Error

F

Fred Block

Hi All,

In VB6 when an error occurred in an application, the IDE stopped and showed
me where the error was. How do I set this in the Visual Studio 2008 IDE?

I'm trapping the error in the Try..Catch..End Try statement but would like
to know exactly what line the failure is occurring on.
 
F

Family Tree Mike

Fred Block said:
Hi All,

In VB6 when an error occurred in an application, the IDE stopped and
showed me where the error was. How do I set this in the Visual Studio 2008
IDE?

I'm trapping the error in the Try..Catch..End Try statement but would like
to know exactly what line the failure is occurring on.


If you examine the exception object, there is a StackTrace property that
tells you the line number. For example, you could do this:

Try
Dim fs As System.IO.FileStream
Dim sr As New System.IO.StreamReader(fs)
Catch ex As Exception
Console.Out.WriteLine(ex.StackTrace.ToString())
End Try
 
J

Jack Jackson

Hi All,

In VB6 when an error occurred in an application, the IDE stopped and showed
me where the error was. How do I set this in the Visual Studio 2008 IDE?

I'm trapping the error in the Try..Catch..End Try statement but would like
to know exactly what line the failure is occurring on.

In the Debug menu item, click on Exceptions (you may have to add it).
Check the appropriate checkboxes.
 
R

rowe_newsgroups

If you examine the exception object, there is a StackTrace property that
tells you the line number.  For example, you could do this:

Try
  Dim fs As System.IO.FileStream
  Dim sr As New System.IO.StreamReader(fs)
Catch ex As Exception
  Console.Out.WriteLine(ex.StackTrace.ToString())
End Try

Also, if you believe the IDE stopped on the incorrect line, you can
use the Call Stack window to "crawl" back through the stack,
inspecting the calls that have been made leading up to the current
breakpoint.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
F

Fred Block

Thanks all of you for replying and helping!

I was able to get the application to break at the line of code causing the
problem. Now to get around the actual issue is another topic.

Merry Christmas!

- Fred
 
T

Teemu

Fred Block said:
Hi All,

In VB6 when an error occurred in an application, the IDE stopped and
showed me where the error was. How do I set this in the Visual Studio 2008
IDE?

I'm trapping the error in the Try..Catch..End Try statement but would like
to know exactly what line the failure is occurring on.

VB6 didn't stop if you had "On Error" statement in your code, Try block is
almost the same in VB 2008.

I usually comment out all Try blocks if I'm debugging my program and I want
to see where errors happen.

Merry Christmas!

-Teemu
 
R

rowe_newsgroups

Thanks all of you for replying and helping!

I was able to get the application to break at the line of code causing the
problem. Now to get around the actual issue is another topic.

Merry Christmas!

I'll take the chance to encourage you to write some unit tests for
your application while you're at it. Properly written unit tests will
be able to tell you exactly where a problem occurred, and since they
can be automated, unit tests will allow you to check any future
updates for breaking issues.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
O

(O)enone

Teemu said:
VB6 didn't stop if you had "On Error" statement in your code

It did if you told it to "Break on all errors." This was an
exceptionally useful feature.
I usually comment out all Try blocks if I'm debugging my program and I
want to see where errors happen.

You'll save yourself an immense amount of time if you just open the
Debug/Exceptions window and tell it to break when a Common Language
Runtime Exception is thrown (check the second box down in the left
column). While that option is selected, the IDE will break as soon as
any exception is encountered, regardless of whether there is a Try block
in effect. I couldn't function without that option! :)
 
H

hawbsys

It did if you told it to "Break on all errors." This was an
exceptionally useful feature.


You'll save yourself an immense amount of time if you just open the
Debug/Exceptions window and tell it to break when a Common Language
Runtime Exception is thrown (check the second box down in the left
column). While that option is selected, the IDE will break as soon as
any exception is encountered, regardless of whether there is a Try block
in effect. I couldn't function without that option! :)

Good tip, thanks.

Hawb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top