File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?" Watch "NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?" New topic
Author

NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Apr 04, 2004
Posts: 815
you have wrong forum geposted


I've heard it takes forever to grow a woman from the ground
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Indeed. Let's move this to JiG(B).


[Jess in Action][AskingGoodQuestions]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Oops, thanks
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272

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.


Mike Gershman
SCJP 1.4, SCWCD in process
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

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


Using the 'exception stack trace'.


Tony Morris
Java Q&A (FAQ, Trivia)
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10


OR



Although I must say that I don't really like either of these solutions.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
excellent, thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NumberFormatException HOW CAN I TELL WHERE IS THE PROBLEM?
 
Similar Threads
Exception handling question K&B
My code isn't running on sites like codechef and oneide
Constructor with a parameter
help with joption pane cancel button
NullPointerException thrown in JOptionPane