|
|
| java help |
Expert:Maurice
Code a catch block that catches a NumberFormatException and then prints the stack trace. |
| Answers |
Hi friend,
Code a catch block that catches a NumberFormatException and prints stack trace :
class NumberFormatExceptionExample { public static void main(String[] args) { String[] ar={"Roseindia", "Hello World", "1234"}; String str=""; int num; for(int count=0;count<ar.length;count++) { System.out.println("Input : " + ar[count]); try { str=ar[count]; num=Integer.parseInt(str); } catch (NumberFormatException e) { // prints the stack trace e.printStackTrace(); } } } }
For more information on Exception Handling in Java visit to :
http://www.roseindia.net/java/exceptions/
Thanks
Vineet
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|