// This code compiles just fine.
static void Main(string[] args)
{
Console.WriteLine("***** Handling Multiple Exceptions *****\n");
Car myCar = new Car("Rusty", 90);
try
{
// Trip Arg out of range exception.
myCar.Accelerate(-10);
}
catch (CarIsDeadException e)
{
Console.WriteLine(e.Message);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine(e.Message);
}
// This will catch any other exception
// beyond CarIsDeadException or
// ArgumentOutOfRangeException.
catch(Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
C H A P T E R 7
■
U N D E R S TA N D I N G S T R U C T U R E D E X C E P T I O N H A N D L I N G
237
8849CH07.qxd 10/1/07 10:38 AM Page 237
Do'stlaringiz bilan baham: |