[prog] Exceptions in Java 1.4.1 -- getMessage()

Sue Stones suzo at bigpond.net.au
Sat Nov 2 12:45:06 EST 2002


If it was me I would work out a sentenec that made sence of the output 
from getMessage()

eg For input string: "foo"  - you get an error because it is not an integer!

sue


On Sat, 2 Nov 2002 01:36, Christina Zeeh wrote:
> 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



More information about the Programming mailing list