|
|
| java help |
Expert:Maurice
Code a catch block that catches a NumberFormatException and then prints the name of the class that the exception was created from along with the message associated with the exception to the standard error output stream.
|
| Answers |
Hi friend,
Code a catch block that catches a NumberFormatException :
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); System.out.println("Numbers are "+num); } catch (NumberFormatException e) { System.out.print("Sorry, \""+str+"\" is not an integer."); System.out.println(" Try again"); System.out.println("->"+e); // -> added to identify this line. 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?
|
|
|
|
|