Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://beginnersbook.com/2013/04/exception-handling-examples/
- Example 3: NumberFormat Exception
- Class: Java.lang.NumberFormatException
- The object of the above built-in class gets created whenever a string is parsed to any numeric variable.
- For E.g. The statement int num=Integer.parseInt ("XYZ") ; would throw NumberFormatException because String “XYZ” cannot be parsed to int.
- Complete Code:
- class ExceptionDemo3
- {
- public static void main(String args[])
- {
- try{
- int num=Integer.parseInt ("XYZ") ;
- System.out.println(num);
- }catch(NumberFormatException e){
- System.out.println("Number format exception occurred");
- }
- }
- }
- Output:
- Number format exception occurred
- class ExceptionDemo3
- {
- public static void main(String args[])
- {
- try{
- int num=Integer.parseInt ("XYZ") ;
- System.out.println(num);
- }catch(NumberFormatException e){
- System.out.println("Number format exception occurred");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement