C
cody
public DateTime Value
{
get
{
try
{
return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text),
int.Parse(tbDay.Text));
}
catch (FormatException)
{
// do stuff here
}
catch (ArgumentException)
{
// do stuff here
}
catch (OverflowException)
{
// do stuff here
}
}
Since there is no good base class (No, I won't catch System.Exception) I
have to catch all three exceptions separately. If all three exceptions
requires the same error handling I have to write the code three times or
have to create a separate method only for this stupid small exception
handling.
Why not one single base-class for all non-fatal SystemExceptions?
There are many other examples, e.g. a simple call to Process.Start which can
throw 4 different exceptions which I have to deal with
(InvalidOperation,Argument,Win32,ObjectDisposed).
Please MS, revise your exception model!
If MS cannot handle this, please allow at least a syntax like
catch (ArgumentException,OverflowException,FormatException)
{
}
{
get
{
try
{
return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text),
int.Parse(tbDay.Text));
}
catch (FormatException)
{
// do stuff here
}
catch (ArgumentException)
{
// do stuff here
}
catch (OverflowException)
{
// do stuff here
}
}
Since there is no good base class (No, I won't catch System.Exception) I
have to catch all three exceptions separately. If all three exceptions
requires the same error handling I have to write the code three times or
have to create a separate method only for this stupid small exception
handling.
Why not one single base-class for all non-fatal SystemExceptions?
There are many other examples, e.g. a simple call to Process.Start which can
throw 4 different exceptions which I have to deal with
(InvalidOperation,Argument,Win32,ObjectDisposed).
Please MS, revise your exception model!
If MS cannot handle this, please allow at least a syntax like
catch (ArgumentException,OverflowException,FormatException)
{
}