Try&catch

try

{

double x;

x = Double.parseDouble("w2");

System.out.println( "The number is " + x );

}

catch ( NumberFormatException e )

{

System.out.println( "Not a legal number." );

}