Object Oriented Programming using C#

(backadmin) #1
Object Oriented Programming using C#
Case Study

11.10 Creating and Handling UnknownClientException


The GetClient() method will generate a KeyNotFoundException if no client exists with the specified ID. If we do not
catch and deal with this exception our program will crash! Furthermore our program will crash as we try to invoke the
DecreaseCredit() method without having a client object to invoke this method on.

To protect against this we need to :-
• Create a new kind of exception (as described in Chapter 9) called UnknownClientException
• tell the ClientBook class to throw this exception if a client is not found
• catch and deal with this exception in the DailyPurge() method.

The first step is simple ....

public class UnknownClientException :ApplicationException
{
public UnknownClientException(String message): base(message)
{
}
}

By 2020, wind could provide one-tenth of our planet’s
electricity needs. Already today, SKF’s innovative know-
how is crucial to running a large proportion of the
world’s wind turbines.
Up to 25 % of the generating costs relate to mainte-
nance. These can be reduced dramatically thanks to our
systems for on-line condition monitoring and automatic
lubrication. We help make it more economical to create
cleaner, cheaper energy out of thin air.
By sharing our experience, expertise, and creativity,
industries can boost performance beyond expectations.
Therefore we need the best employees who can
meet this challenge!
The Power of Knowledge Engineering

Brain power


Plug into The Power of Knowledge Engineering.
Visit us at http://www.skf.com/knowledge

Please click the advert

Free download pdf