public class PrintInt // an exercise in catching exceptions
{
// -------------- the MAIN method --------------------------
public static void main(String [] args) throws Exception
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader inComing = new BufferedReader(isr);
PrintWriter outGoing = new PrintWriter(System.out, true);
int x=0;
String s="";
outGoing.println("Please enter an integer.");
try
{
s = inComing.readLine();
x = Integer.parseInt(s);
outGoing.println("The integer was " + x);
}
catch (NumberFormatException e)
{
outGoing.println("Sorry, you didn't enter an integer.");
outGoing.println("You caused the following error " + e);
}
catch (Exception e)
{
outGoing.print("Sorry, ");
outGoing.println("you caused the following error " + e);
}
}
} // end of class PrintInt