This method demonstrates calling a method that might throw
an exception, and catching the resulting exception.
Object o = null;
for (int i=0; i<5; i++) {
try {
o = makeObj(i);
} catch (IllegalArgumentException e) {
System.err.println("Error: (" + e.getMessage() + ").");
return; // cut off println below if makeObj failed.
} finally {
System.err.println("All done");
if (i==null)
System.exit(0);
}
System.out.println(o); // process the created object in some way
}