Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?  RSS feed

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

can someone help me on this one:

if the program below throws an exception how can i tell with which INTEGER is the problem?
e.getSource() - will tell me what was the value but not with which integert.


public class prog30
{
public static void main (String args[])
{
int i;
int x;

try
{
i = Integer.parseInt(args[0]);
x = Integer.parseInt(args[1]);

}
catch (NumberFormatException e)
{
System.out.println("problem with argumnet ???" + e.???);

}
}
}
 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have wrong forum geposted
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Let's move this to JiG(B).
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, thanks
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This code shows two methods. You can set flags ("itsMe") just before each conversion or you can scan the stack trace and locate the source program line number where the error occurred.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if the program below throws an exception how can i tell with which INTEGER is the problem?



Using the 'exception stack trace'.
 
Sheriff
Posts: 9087
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


OR



Although I must say that I don't really like either of these solutions.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
excellent, thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!