mirror of
https://github.com/corda/corda.git
synced 2024-12-30 17:57:02 +00:00
9bb3d6b972
git-subtree-dir: sgx-jvm/avian git-subtree-mainline:f978eab8d1
git-subtree-split:09e4fe60d0
64 lines
1.1 KiB
Java
64 lines
1.1 KiB
Java
public class Exceptions {
|
|
static class ThrowError {
|
|
static {
|
|
if (true) throw new AssertionError();
|
|
}
|
|
|
|
static void foo() { }
|
|
}
|
|
|
|
static class ThrowException {
|
|
static {
|
|
if (true) throw new RuntimeException();
|
|
}
|
|
|
|
static void foo() { }
|
|
}
|
|
|
|
private static void evenMoreDangerous() {
|
|
throw new RuntimeException("chaos! panic! overwhelming anxiety!");
|
|
}
|
|
|
|
private static void moreDangerous() {
|
|
evenMoreDangerous();
|
|
}
|
|
|
|
private static void dangerous() {
|
|
moreDangerous();
|
|
}
|
|
|
|
private static void expect(boolean v) {
|
|
if (! v) throw new RuntimeException();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
boolean threw = false;
|
|
try {
|
|
dangerous();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
threw = true;
|
|
}
|
|
expect(threw);
|
|
threw = false;
|
|
|
|
try {
|
|
ThrowError.foo();
|
|
} catch (AssertionError e) {
|
|
e.printStackTrace();
|
|
threw = true;
|
|
}
|
|
expect(threw);
|
|
threw = false;
|
|
|
|
try {
|
|
ThrowException.foo();
|
|
} catch (ExceptionInInitializerError e) {
|
|
e.printStackTrace();
|
|
threw = true;
|
|
}
|
|
expect(threw);
|
|
}
|
|
|
|
}
|