B
brunft
I was testing this with .NET Framework 2.0.
Exceptions in the Elapsed event handler of a System.Timers.Timer are
ignored, they are not handled by the runtime and not reported (when
running outside of VS.NET) either. Ther Timer continues as if nothing
happened.
Is this the desired behaviour, because this would have very negative
impact on analysis of unexpected errors?
Am i missing any design directives concerining the exception handling
in a System.Timers.Timer object?
The following example demonstrates, what i am speaking of
using System;
using System.Timers;
class TimerTest
{
Timer myTimer;
public TimerTest() {
myTimer = new Timer(1000);
myTimer.Enabled = true;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
}
void myTimer_Elapsed(object sender, ElapsedEventArgs e) {
Console.WriteLine("TimerTest: Simulate an unexpected exception
....");
// Simulate unexpected exception ...
throw new Exception("Elapsed test exception.");
}
}
class Program
{
static void Main(string[] args) {
TimerTest timerTest = new TimerTest();
Console.WriteLine("TimerTest running. Press any key to
proceed");
Console.Read();
}
}
As already said, the exception is catched inside of VS.NET 2005 by the
Exception Assistant, when debugging.
Thanks & greets
brunft
Exceptions in the Elapsed event handler of a System.Timers.Timer are
ignored, they are not handled by the runtime and not reported (when
running outside of VS.NET) either. Ther Timer continues as if nothing
happened.
Is this the desired behaviour, because this would have very negative
impact on analysis of unexpected errors?
Am i missing any design directives concerining the exception handling
in a System.Timers.Timer object?
The following example demonstrates, what i am speaking of
using System;
using System.Timers;
class TimerTest
{
Timer myTimer;
public TimerTest() {
myTimer = new Timer(1000);
myTimer.Enabled = true;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
}
void myTimer_Elapsed(object sender, ElapsedEventArgs e) {
Console.WriteLine("TimerTest: Simulate an unexpected exception
....");
// Simulate unexpected exception ...
throw new Exception("Elapsed test exception.");
}
}
class Program
{
static void Main(string[] args) {
TimerTest timerTest = new TimerTest();
Console.WriteLine("TimerTest running. Press any key to
proceed");
Console.Read();
}
}
As already said, the exception is catched inside of VS.NET 2005 by the
Exception Assistant, when debugging.
Thanks & greets
brunft