all groups > visual studio .net debugging > july 2007 >
You're in the

visual studio .net debugging

group:

Exceptions not trapped in VS.NET 2005


Exceptions not trapped in VS.NET 2005 HoloDoc
7/16/2007 6:52:01 PM
visual studio .net debugging:
Hi,

Running VS.NET 2005 SP1. Just recently moved from VS.NET 2003.

Have following simple code. Basically when form loads it opens a web site
into control WebBrowser1. This works fine. Then use event
WebBrowser1_DocumentCompleted to perform actions once the document has loaded.

The problem is any exceptions thrown after this are no longer handled
correctly by the debugger. Instead the exception is written to the output
window and the application just shows the form. I am expecting the
application to break at invalid code so I can diagnose the problem. I have
placed a invalid substring to force the error. If we force error before
webpage is loaded the debugger breaks correctly.

Have done much testing and it all is related to using DocumentCompleted.
Thanks in advance.


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'This error would generate an exception and break debugger.
'Dim x As String
'Console.WriteLine(x.Substring(0, 34))
Me.WebBrowser1.Navigate("http://any-website")

End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal
e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles
WebBrowser1.DocumentCompleted

'Fake an error
Dim x As String
Console.WriteLine(x.Substring(0, 34))
End Sub

End Class
RE: Exceptions not trapped in VS.NET 2005 Arindrajit Biswas
8/7/2007 2:16:03 PM
Just add a Try Catch block around your code as follows:

Try
Dim x As String
Console.WriteLine(x.Substring(0, 34))
Catch ex as Exception
Console.WriteLine(ex.StackTrace)

Then put a breakpoint in catch block. Debugger will break.


[quoted text, click to view]
RE: Exceptions not trapped in VS.NET 2005 HoloDoc
8/7/2007 3:26:01 PM
The problem was the debugger didn't find the error so i would never know it
occurred. Placing a catch is ok if u know the error is there and want to
handle it.

I have since found if i go into Debug | Exceptions and check 'thrown'
against CLR Exceptions it does pick them up. Why this is not the default i'll
never know.

Thanks.

[quoted text, click to view]
AddThis Social Bookmark Button