public class ExceptionDemo {
public static void main(String[] args) {
handleArgs(args);
}
public static void handleArgs(String[] args) {
if(args.length == 0)
throw new RuntimeException("Must pass an argument to the
function.");
if(args[0].length() <= 1)
throw new RuntimeException("Argument must be at least 2
characters.");
}
}
public static void main(String[] args) {
try {
handleArgs(args);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void main (String[] args) throws Exception {
try {
handleArgs(args);
} finally {
System.out.println("We handled args");
}
}
public static void fileRead (File file) throws Exception {
Reader in = null;
try {
in = new InputStreamReader(new FileInputStream("test.txt"));
System.out.println(in.read());
} finally {
if (in != null) {
in.close();
}
}
}