Consider the following program:
public class Main { public static void main(String []args) { try { assert false; } catch(RuntimeException re) { System.out.println("RuntimeException"); } catch(Exception e) { System.out.println("Exception"); } catch(Error e) { // LINE A System.out.println("Error" + e); } catch(Throwable t) { System.out.println("Throwable"); }//from www . j a va2 s. com } }
This program is invoked in command line as follows:
java Main
Choose one of the following options describes the behavior of this program:
f)
By default, assertions are disabled.
If -ea (or the -enableassertions
option to enable assertions), then the program would have printed "Error"
since the exception thrown in the case of assertion failure is java.lang.AssertionError, which is derived from the Error class.