What is the purpose of assertions?
Consider the following code:
public class ExceptionTest { public static void main(String[] args) { try { throw new Exception("Test"); } catch (Exception e) { try { throw new RuntimeException("Inner"); } catch (RuntimeException re) { System.out.print(re.getMessage() + " "); } } finally { System.out.print("Finally "); } System.out.print("End"); }}
What is the output?
Consider the following code.
public class ExceptionTest { public static void main(String[] args) { try{ throw new MyException(); }catch(Exception e){ System.out.print(e.getMessage()); } } static class MyException extends Exception{ MyException(){super("Custom Exception");} }}
public class ExceptionTest { public static void main(String[] args) { try { try { throw new Exception("Inner"); } finally { System.out.print("F"); } } catch (Exception e) { System.out.print("C"); } System.out.print("E"); }}
public class ExceptionTest { public static void main(String[] args) { try { assert false; System.out.print("A"); } catch (AssertionError e) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); }}
If assertions are enabled using -ea, what is the output?
-ea
What is the purpose of multiple catch blocks?
catch
By default, are assertions enabled or disabled in Java?
How do you create a custom exception in Java?
public class ExceptionTest { public static void main(String[] args) { try { System.out.print("1"); throw new Exception(); } catch (Exception e) { System.out.print("2"); return; } finally { System.out.print("3"); } System.out.print("4"); }}
public class ExceptionTest { public static void main(String[] args) { try { method1(); } catch (Exception e) { System.out.print("C"); } } static void method1() throws Exception { try { throw new RuntimeException("A"); } catch (RuntimeException e) { System.out.print("B"); throw new Exception("D"); } finally { System.out.print("E"); } }}
public class ExceptionTest { public static void main(String[] args) { try { System.out.print("A"); throw new RuntimeException(); } finally { System.out.print("B"); } }}
public class ExceptionTest{ public static void main(String[] args){ try{ System.out.print("1"); int a = 1/0; }catch(RuntimeException e){ System.out.print("2"); }catch(Exception e){ System.out.print("3"); }finally{ System.out.print("4"); } }}What is the output?
Which keyword is used to declare that a method might throw an exception?
Which keyword is used to define an assertion in Java?
public class ExceptionTest { public static void main(String[] args) { try { System.out.print("A"); int x = 10 / 0; System.out.print("B"); } catch (ArithmeticException e) { System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); }}