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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -