java - NumberFormatException - how to get the result and suppress the exception? -
I want to use the result of the conversion Can I do this?
int num1 = integer.paint (a.getText ()); Int number 2 = integer. Percent (b.gettext ()); C.setText (String.valueOf (number1 + NUM2));
1 Try
block all code: < / H3> Try {int num1 = integer.paint (a.getText ()); Int number 2 = integer. Percent (b.gettext ()); C.setText (String.valueOf (num1 + num2)); } Hold (NumberFormatException ex) {// Ignore? // the handle? Ex.printStackTrace (); }
- hold
- hold
- Int num1; {Num1 = integer. Try endpoint (a.getText ()); } Hold (NumberFormatException ex) {// Ignore? // the handle? A.setText (0); Num1 = 0; } 3write string
before parsing:
int num1 = a.getText (). Matches ("-? \\ d +")? Integer.center (a.gettext ()): 0 / * arbitrary default value * /;
Any of these options may work; Specifically, this option should depend on what you are actually trying to achieve.
Comments
Post a Comment