Define an alternative signature for the methods pairIn and readPair, whose return value indicates when no matching pair is available. The return value should be defined as an enumerated type whose values can be ok and wait. Discuss the relative merits of the two alternative approaches. Which approach would you use to indicate an error such as a key that contains illegal characters?

What will be an ideal response?

```
enum status { ok, wait};
status pairIn (in Key key, out Value value);
status readPair (in Key key, out Value value);
```
It is generally more complex for a programmer to deal with an exception that an ordinary return because exceptions break the normal flow of control. In this example, it is quite normal for the client calling pairIn to find that the server hasn’t yet got a matching pair. Therefore an exception is not a good solution.
For the key containing illegal characters it is better to use an exception: it is an error (and presumably an unusual occurrence) and in addition, the exception can supply additional information about the error. The client must be supplied with sufficient information to recognise the problem.

Computer Science & Information Technology

You might also like to view...

Which of the following will Excel display if a cell width is too narrow to display an entire number?

a. #VALUE? b. #NUM! c. #N/A d. ######

Computer Science & Information Technology

Sketch out in pseudo-code how you would add a simple round robin scheduler to the Xen hypervisor

What will be an ideal response?

Computer Science & Information Technology