• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?

 
Peter Primrose
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.???);

}
}
}
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have wrong forum geposted
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
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
 
Mike Gershman
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.
 
Tony Morris
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'.
 
Marilyn de Queiroz
Sheriff
Posts: 9065
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