Specifications
Sun Services
Java™ Programming Language
Module 8, slide 7 of 25
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
The try-catch Statement
1 public class AddArguments2 {
2 public static void main(String args[]) {
3 try {
4 int sum = 0;
5 for ( String arg : args ) {
6 sum += Integer.parseInt(arg);
7 }
8 System.out.println("Sum = " + sum);
9 } catch (NumberFormatException nfe) {
10 System.err.println("One of the command-line "
11 + "arguments is not an integer.");
12 }
13 }
14 }
java AddArguments2 1 two 3.0 4
One of the command-line arguments is not an integer.










