December
1999 QUESTION 3 Total Marks: 15 Marks |
Click here to access
other questions
SUGGESTED SOLUTIONS |
(a) |
(i)State when an exception is thrown
in a Java program.[1 mark ] (ii)Briefly state the purpose of an
exception handler .[1 mark ]
|
[2] | ||||||||||||||||||
(b) |
(i)Declare an exception class ,called
NoSuchAttribute ,which contains the following members:
And the following
marking scheme should be used: (ii)Write a method,called FooBar ,which
takes three parameters,x and y ,and Test of types String ,Object ,and
boolean respectively.Your method should simply allocate and throw
as an exception an object of type NoSuchAttribute ,if the parameter
Test is False .[4 marks ]
And the following
marking scheme should be used: (iii)Write a method,called TryMyException
,the signature of which is given below, which will try to execute
your method FooBar .The method should call the method Failure ,the
signature of which is given below,if the exception NoSuchAttribute
is caught,and call the method Success ,the signature of which is given
below,regardless of which exceptions are caught.You are not required
to implement Success or Failure .
And the following
marking scheme should be used: |
[13] |