A simple test case to demonstrate my 2 problems:
public class Numbers {
private static void usage() {
System.err.println("Usage: java " + getClass().getName() + " range");
System.exit(1);
}
public static void main(String[] args) throws IOException {
try {
int range = Integer.parseInt(args[0]);
} catch (Exception e) {
usage();
}
}
}
- Can't call
getClass()
from a static method - If no arguments have been supplied at the command line, I'll get
ArrayIndexOutOfBoundsException
message instead of theusage()
output. Why doesn't catch (Exception e) catch it?