Processing Multiple Exceptions
In its simplest form, a try block has a single catch block. In reality, you often run into a situation
where the statements within a try block could trigger numerous possible exceptions. Create a new
C# Console Application project named ProcessMultipleExceptions, add your existing Car, Radio,
and CarIsDeadException classes to the new project (via Project ➤ Add Existing Item), and update
your namespace names accordingly.
Now, update the Car’s Accelerate() method to also throw a base class library–predefined
ArgumentOutOfRangeException if you pass an invalid parameter (which we will assume is any value
less than zero):
Do'stlaringiz bilan baham: |