If you don’t provide a valid long as input it throws NumberFormatException. See below:
long converted = Long.valueOf( "3" );
System.out.println( converted );
Prints 3
try{
long converted = Long.valueOf( "TEST" );
System.out.println( converted );
}
catch( NumberFormatException e ){
System.out.println( "Your input is wrong.." );
}
This throws NumberFormatException, it’s because not a valid number. And prints “Your input is wrong..”
solved Why do I get a NumberFormatException when I convert this