corda/sgx-jvm/avian/test/Exceptions.java

64 lines
1.1 KiB
Java
Raw Normal View History

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() { }
}
2007-06-30 02:39:01 +00:00
private static void evenMoreDangerous() {
throw new RuntimeException("chaos! panic! overwhelming anxiety!");
}
private static void moreDangerous() {
2007-07-02 01:42:35 +00:00
evenMoreDangerous();
2007-06-30 02:39:01 +00:00
}
private static void dangerous() {
moreDangerous();
}
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
2007-06-30 02:39:01 +00:00
public static void main(String[] args) {
boolean threw = false;
2007-07-11 04:19:26 +00:00
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;
2007-07-11 04:19:26 +00:00
}
expect(threw);
2007-06-30 02:39:01 +00:00
}
}