例外処理を伝播させる方法を実装しました。(あくまで実験です)
class NyException extends RuntimeException{}
class A{
void bar() {
try {
//クラスをまたがって例外処理を伝播させる。三項演算子で判定している
throw (1 + Math.random()) * 100 > 0 ? new NyException():new RuntimeException();
}catch (NullPointerException ex) {
System.out.println("A ");
}
}
}
public class Test {
public static void main(String[] args) {
try {
new A().bar();
} catch (NyException ex) {
System.out.println("C ");
}
}
}