Don't debug in try-catch block
-
This didn't happen in vs2005 I don't think, but vs2008 throws exceptions in debug on errors within my try-catch blocks. Can I turn that off? Thanks
That depends on which half of the Try/Catch the error occurs in. VS won't stop on an exception thrown inside a Try block. It WILL stop on an exception thrown in the Catch or Finally blocks.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
That depends on which half of the Try/Catch the error occurs in. VS won't stop on an exception thrown inside a Try block. It WILL stop on an exception thrown in the Catch or Finally blocks.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Not so... my errors are being thrown within the try section. FI: Try Console.WriteLine(TTDG.Rows(1000).Cells(100).Value) Catch ex As Exception End Try
-
Not so... my errors are being thrown within the try section. FI: Try Console.WriteLine(TTDG.Rows(1000).Cells(100).Value) Catch ex As Exception End Try
If you have no code in your catch block then you will "eat"/ignore any error that occurs within the try. Been this way since at least 2003.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
If you have no code in your catch block then you will "eat"/ignore any error that occurs within the try. Been this way since at least 2003.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
All I can tell you is that it is definitely happening for me. No code in the catch, but the error is trapped in the try.
-
All I can tell you is that it is definitely happening for me. No code in the catch, but the error is trapped in the try.
ok but how many statements are you executing within the try. as soon as an exception occurs, you get kicked out of the try statements 4 and 5 below will not be executed if an exception occurs at statement 3 try exec 1 exec 2 exec 3 -> exception happens here exec 4 exec 5 catch end try
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
ok but how many statements are you executing within the try. as soon as an exception occurs, you get kicked out of the try statements 4 and 5 below will not be executed if an exception occurs at statement 3 try exec 1 exec 2 exec 3 -> exception happens here exec 4 exec 5 catch end try
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
What is the problem for me is that the exception within the try is thrown. The debugger stops and shows me the error. I thought that exceptions within the try would be ignored. Thanks
-
What is the problem for me is that the exception within the try is thrown. The debugger stops and shows me the error. I thought that exceptions within the try would be ignored. Thanks
for anyone to answer this in any detail you should show the actual code (inside PRE tags!) AND the exact exception information. And you should have done this from the start, 3 hours ago. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
for anyone to answer this in any detail you should show the actual code (inside PRE tags!) AND the exact exception information. And you should have done this from the start, 3 hours ago. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
OK, here's one simple example
Sub test()
Dim x
Try
Console.WriteLine(x(0))
Catch ex As ExceptionEnd Try
end sub
Error thrown is: Object variable or With block variable not set.
-
OK, here's one simple example
Sub test()
Dim x
Try
Console.WriteLine(x(0))
Catch ex As ExceptionEnd Try
end sub
Error thrown is: Object variable or With block variable not set.
Using VB.NET 2008 Express, this
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x Try Console.WriteLine(x(0)) Catch exc As Exception Console.WriteLine(Exc.ToString()) End Try End Sub
gives me 1. a compilation warning ("Variable 'x' is used before it has been assigned a value. A null reference exception could result at runtime."); you should not ignore warnings. 2. a run-time exception, which gets shown inside the catch block, as I would expect. ("System.NullReferenceException: Object variable or With block variable not set." + stack traceback) All looks normal to me. If yours behaves differently, there must be either a different setting (maybe under Tools/Options), although I wouldn't know which, or a general problem with your copy of VS. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
Using VB.NET 2008 Express, this
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x Try Console.WriteLine(x(0)) Catch exc As Exception Console.WriteLine(Exc.ToString()) End Try End Sub
gives me 1. a compilation warning ("Variable 'x' is used before it has been assigned a value. A null reference exception could result at runtime."); you should not ignore warnings. 2. a run-time exception, which gets shown inside the catch block, as I would expect. ("System.NullReferenceException: Object variable or With block variable not set." + stack traceback) All looks normal to me. If yours behaves differently, there must be either a different setting (maybe under Tools/Options), although I wouldn't know which, or a general problem with your copy of VS. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
OK, thanks for your help! Happy holidays!