Building Custom Exceptions, Take Two
The current CarIsDeadException type has overridden the System.Exception.Message property in
order to configure a custom error message and supplied two custom properties to account for addi-
tional bits of data. In reality, however, we are not required to override the virtual Message property,
as we could simply pass the incoming message to our parent’s constructor as follows:
public class CarIsDeadException : ApplicationException
{
private DateTime errorTimeStamp;
private string causeOfError;
public DateTime TimeStamp
{
get { return errorTimeStamp; }
set { errorTimeStamp = value; }
}
public string Cause
{
get { return causeOfError; }
set { causeOfError = value; }
}
public CarIsDeadException() { }
Do'stlaringiz bilan baham: |