Skip to content

Instantly share code, notes, and snippets.

@DasBrain
Created July 7, 2022 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DasBrain/61d2859a66183d29cb2eb9bf4cc1c81b to your computer and use it in GitHub Desktop.
Save DasBrain/61d2859a66183d29cb2eb9bf4cc1c81b to your computer and use it in GitHub Desktop.
package pkg;
public class Exceptions {
private static class EBase extends Exception {
public void m() {}
}
public static class E1 extends EBase {}
public static class E2 extends EBase {}
}
import pkg.Exceptions;
public class ExceptionsTest {
public static void main(String[] args) {
try {
m1();
} catch (Exceptions.E1 | Exceptions.E2 e) {
e.m();
}
}
private static void m1() throws Exceptions.E1, Exceptions.E2 {
throw new Exceptions.E1();
}
}
> java ExceptionsTest
Exception in thread "main" java.lang.IllegalAccessError: failed to access class pkg.Exceptions$EBase from class ExceptionsTest (pkg.Exceptions$EBase and ExceptionsTest are in unnamed module of loader 'app')
at ExceptionsTest.main(ExceptionsTest.java:8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment