corda/sgx-jvm/avian/test/Exceptions.java
Andras Slemmer 9bb3d6b972 Add 'sgx-jvm/avian/' from commit '09e4fe60d01f4f4bfb6b2976973bb4913ef61edc'
git-subtree-dir: sgx-jvm/avian
git-subtree-mainline: f978eab8d1
git-subtree-split: 09e4fe60d0
2017-03-13 12:18:24 +00:00

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);
}
}