We can find out more about the Exception that is thrown by BufferedReader.readLine() by going to [ index.html ] the documentation and searching it.
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!
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*/
}