Java Program:
/* Java Application that reads a value from user and tries to convert and print numeric value and if conversion fails, handles the error appropriately and prints appropriate error message */
import java.util.*;
class TryToParseString
{
//Main method
public static void main(String args[])
{
String input;
int value;
Scanner sc = new Scanner(System.in);
try
{
//Reading a value from user
System.out.print("\n Enter an integer value: ");
input = sc.nextLine();
//Trying to parse the input to integer
value = Integer.parseInt(input);
//If conversion success, prints the converted integer value
System.out.println("\n\n Integer Value: " + value);
}
catch(NumberFormatException ex)
{
//If conversion fails, prints appropriate message to console
System.out.println("\n\n Error: Non-Numeric Value entered.... \n");
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sample Output: