We can find out more about the Exception that is thrown by
BufferedReader.readLine() by going to
[ index.html ]
the documentation and searching it.
Question 1 Definitions
Define: exception, exception handler, raising an exception, disabling an exception, built-in exception, event, and event handler
Question 2 Design issues for Exceptions
List the design issues for exceptions.
Question 3 Template for a question
Compare, in detail, the exception-handling features of <X> with those of <Y> .... where X and Y are different languages taken from C++, Ada, and Java.
Question 4 Updating code to use exceptions
Here is a simple loop that reads data in a C-like language:
while ( input(data) )
{ process(data);
}where data is a variable of type D. The above code uses a function
int input(D & d);that returns 0 when something goes wrong and some integer other than 0 when all goes well.
a. What is the semantic mode and purpose of the formal parameter d in the int input(...) function above?
Suppose that this function is modified for a C++ or Java-like language to use an exception E instead:
D new_input() throws E;
b. What are the arguments for new_input() and what is returned by new_input() under normal circumstances? How might you use it?
c. Rewrite the loop above so that it works with new_input() rather than the old input(d).
Note: Exceptions were added to C++ in 1996..1998. The libraries gradually caught up. Applications are still catching up. Your first C or C++ job may be making changes just like the above!
Question 5 Event Listener
Explain each line in the following Java code ( ... hides some details):
class Widget extends JApplet implements ItemListener{
...
public void init(){
...
myButton.addItemListener( this );
...
}//end of init
...
public void itemStateChanged ( ItemEvent e){
...
}//end of itemStateChanged
...
}//end class WidgetDraw a diagram of Widget as a class that is a special Kind of JApplet and implements the ItemListener interface.
try
{
while ( true )
{
process(new_input());
}
}
catch( E e )
{
/*do nothing*/
}