import java.io.*;
public class TryCatchExample
{
public static void main (String args[]) throws IOException
{
BufferedReader HelloWorld = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter A Number: ");
try
{
int GalaxyNumber = Integer.parseInt(HelloWorld.readLine());
}
catch (NumberFormatException ShowError)
{
System.out.println("Enter A Number: ");
}
}
you can also have...
catch (NumberFormatException ShowError)
{
System.out.println(ShowError);
}
instead of...
catch (NumberFormatException ShowError)
{
System.out.println("Enter A Number: ");
}
... to know the error.
No comments:
Post a Comment