Help with Catching Exceptions
I am trying to make this program catch if a character is entered instead of a number. I get a run-time error on line 23, the line that I try to read "something" again. HELP?!??!
Code:
import java.util.Scanner;
import java.io.*;
class TRY
{
public static void main(String [] args)
{
Scanner reader = new Scanner(System.in);
double something;
//this trys to catch if a charcter is inputed
try
{
something = reader.nextDouble();
}
catch (Exception e)
{
System.out.println("Not a number.");
}
something = reader.nextDouble();
System.out.println(something);
}
}
Thanks!