August
1999 QUESTION 3 Total Marks: 20 Marks |
Click here to access other
questions
Click to access |
(a) | Define what is meant by the term exception
with reference to the Java programming language.
|
[2] |
(b) | Give two examples of abnormal conditions which
may disturb the normal flow of program execution.
|
[2] |
(c) | State the purpose of an exception
class.
|
[2] |
(d) | State the purpose of an error class.
|
[2] |
(e) | Consider the following Java class definition : public class OutOfRange extends Exception { public String GetReason() { } (i) Give the definition of a Java class, called MyClass which will contain a constructor function taking two integer parameters a and b, and a String returning function Foo, which is capable of throwing an exception of type OutOfRange. (ii) Using the Java keyword throw, define the member function Foo such that it will throw the exception OutOfRange if and only if param is equal to or greater than limit, with the string message "parameter out of range". (iii) Using the keyword try and catch, implement the constructor function such that it will try to ensure a is b, and will catch the exception, printing out the reason if it is not.
|
[4]
[4] |