Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Failed to convert Java string to int. How to not throw an exception?
Failed to convert Java string to int. How to not throw an exception?
It's simple, you will definitely throw an exception, but you can catch it without stopping the program because of the exception. Use the try cathy statement

like this

Try {

integer a = integer . parse int(str);

}

Catch (exception e)

System.out.println ("String conversion to integer failed");

}

After throwing an exception, if you want to handle other logic, you can write the logic in the catch statement block.

I hope I can help you, thank you