import java.io.FileReader; import java.io.IOException; /** * Bad exception handling * * Problem is that rather than handling the issue, the main method * simply throws it on, for someone else to handle. Doing this allows * the program to compile. BUT, there is no one to catch something * thrown by main (more or less by definition). Hence, the program * dies in an uncontrolled manner. Unacceptable. * * Created: Jan 2022 * @author gtowell */ public class ExBad2 { /** * A function that opens a FileReader -- for no real reason * @param filename the name of the file to try to open * @throws IOException */ public void doo(String filename) throws IOException { FileReader bb = new FileReader(filename); } public static void main(String[] args) throws IOException { ExBad2 ex = new ExBad2(); ex.doo("20"); } }