[prog] Exceptions in Java 1.4.1 -- getMessage()
Christina Zeeh
lists at tuxtina.de
Fri Nov 1 16:36:40 EST 2002
Hi,
I hava a program that gets several command line arguments and needs to
catch exceptions when something is wrong with the arguments and output
an "informative" error message. The problem is: all my pretty error
messages that use Throwable's getMessage() method are looking a lot
different on Java 1.4.1 than on older platforms. To illustrate that,
here is a simple example:
public class Test{
public static void main(String[] args){
try{
int myNumber = Integer.parseInt(args[0]);
myNumber++;
System.out.println(myNumber);
}
catch (NumberFormatException e){
System.err.println(e.getMessage() + " is not an integer!");
System.exit(1);
}
}
}
The following output is produced if the program is run on Java < 1.4.1:
> java Test 22
23
> java Test foo
foo is not an integer!
When run on Java 1.4.1, the following output results:
> java Test 22
23
> java Test foo
For input string: "foo" is not an integer!
So the result of "getMessage()" is a lot different on Java 1.4.1. Any
ideas how to get the same output on both platforms? Or any other
suggestions what I can do differently? I need to output "informative"
error messages when something is wrong with the command line arguments.
Thanks for any help ...
Christina
--
"I smile because I have no idea what's going on."
More information about the Programming
mailing list