By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,256 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,256 IT Pros & Developers. It's quick & easy.

Debugger doesnt catch exceptions in timer code

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Sam Miller" <sa*****@ansync.com> wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #2

P: n/a
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/...s/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

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
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
"Sam Miller" <sa*****@ansync.com> wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
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


Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.