Skip to content

Files

Latest commit

 

History

History
59 lines (48 loc) · 1.07 KB

errors.md

File metadata and controls

59 lines (48 loc) · 1.07 KB

Java is weird.

Errors

Finally

System.out.print('a');
try {
    int b = 1 / 0;
} catch(NullPointerException c){
    System.out.print('d');
} finally {
    System.out.print('e');
}                              // ae and (ArithmeticException)

System.out.print('a');
try {
    int b = 1 / 0;
} catch(ArithmeticException c){
    System.out.print('d');
} finally {
    System.out.print('e');
}                              // ade

Finally return

boolean getValue(){
  try {
    return true;
  } finally {
    return false;
  }
}
getValue();          // false

Error Inheritance

interface A {
    void func() throws ArithmeticException, ArrayIndexOutOfBoundsException;
}

interface B {
    void func() throws ArrayIndexOutOfBoundsException, IllegalArgumentException;
}

interface C extends A, B {
    void func() throws ArrayIndexOutOfBoundsException;           // Throws intersection of exceptions
}

class D implements C {
    @Override
    public void func() throws ArrayIndexOutOfBoundsException { } // Throws intersection of exceptions
}