Simple 'Try and Catch' Example


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.

Extended Search

Custom Search
Hello World