Debugger doesnt catch exceptions in timer code

  • Thread starter Thread starter Sam Miller
  • Start date Start date
S

Sam Miller

Normally the debugger (visual studio .net environment) is good at pointing
out the line of code that caused an exception.... except when that code is
executed as part of a timer handler. In the case of the code below the
exception is handled by a little dialog that tries to tell me how to switch
on jitDebugging. (which, if I am doing it correctly doesn't seem to help).
All three options are checked under
Tools->Options->Debugging->"Just-In-Time". The commented out version
doesn't seem to even generate an exception (or write anything to the
console). Any ideas? pointers to MSDN articles?

Module startup

Sub main()

Dim myTest As New testTimer()

Application.Run()

End Sub

End Module

'-----------------------------------------------------------------

'Imports System.Timers

Public Class testTimer

'WithEvents pollTimer As System.Timers.Timer

WithEvents pollTimer As System.Windows.Forms.Timer

Sub New()

'pollTimer = New System.Timers.Timer()

pollTimer = New System.Windows.Forms.Timer()

'pollTimer.Interval = 100

'pollTimer.AutoReset = True

pollTimer.Enabled = True

End Sub

'Sub TimerElapsed(ByVal sender As System.Object, ByVal e As
ElapsedEventArgs) Handles pollTimer.Elapsed

Sub TimerTick(ByVal sender As System.Object, ByVal e As EventArgs) Handles
pollTimer.Tick

Console.WriteLine("hello")

Throw New System.Exception()

End Sub

End Class
 
It looks like you are throwing an exception and you don't have any handlers
to deal with it. If the caller doesn't have a wrapper, every time the timer
ticks its going to crash. If I may ask, why are you throwing that
exception?

Wrap the code in exception handlers wherever you think the problem is and
then use exception.ToString to find out what it is. It will give you the
stack trace as well as the line number. I suspect you are getting the
exception before your breakpoint is being hit.

HTH,

Bill
 
Sorry,

More information:
I am throwing the exception as a way of simulating
some-nasty-programmer-error that happens during development. NORMALLY when
this happens I get a nice dialog box and then a yellow line hightlighting
the line that caused the problem. This is real handy. HOWEVER, When
something nasty happens in my timer code I get an unhelpful dialog box such
as is described here:
http://www.wintellect.com/resources/newsletters/articles/appsdie.aspx

I'd realy like to have my favorite yellow line instead. Is this a bug in
the .Net runtime not making use of the default unhandled exception handler?

Sam
 
Back
Top