// Throw the custom CarIsDeadException.
public void Accelerate(int delta)
{
...
CarIsDeadException ex =
new CarIsDeadException (string.Format("{0} has overheated!", petName),
"You have a lead foot", DateTime.Now);
ex.HelpLink = "http://www.CarsRUs.com";
throw ex;
...
}
To catch this incoming exception, your catch scope can now be updated to catch a specific
CarIsDeadException type (however, given that CarIsDeadException “is-a” System.Exception, it is still
permissible to catch a System.Exception as well):
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Custom Exceptions *****\n");
Car myCar = new Car("Rusty", 90);
try
{
Do'stlaringiz bilan baham: |