0

私はこのコードを持っています:

public class C implements Closeable{
private Integer i = 0;
public C () {
}
public C (Integer i) {
this.i = i;
}
@Override
public void close() throws IOException {
System.out.println("close " + this.i);
}
public void m1(C other){
System.out.println("m1 " + this.i + " " + other.i);
}
public static void main(String[] args) {
C c1 = new C(1);
try (C c2 = new C(2); C c3 = null){
c1.m1(c2);
c2.m1(new C());
c3.m1(c1);
}
catch(IllegalArgumentException e) {
System.out.println("illegal argument exception");
}
catch(NullPointerException e) {
System.out.println("null pointer exception");
}
catch(Exception e) {
System.out.println("exception");
}
finally {
System.out.println("finally");
}
System.out.println("end");

実行すると、次の出力が得られます。

} m1 1 2 m1 2 0 close 2 ヌルポインタ例外 最後に終了

私の質問は、実行前に出力がどのように見えるかを知るのに役立つ「アルゴリズム」はありますか? この場合、クローズ可能な(または自動クローズ可能なオブジェクト)があると思います。

より明確にするために、次のことを考えます。 1.例外が発生し、最終的にキャッチしていない場合、プログラムは最初のキャッチを見つけて呼び出し、この例外を解決します。等

どうもありがとう!

4

0 に答える 0