728x90
1.
class Ex extends Exception{}
public class ExerciseChp9_6_1 {
public static void main(String[] args) {
System.out.println("Entering first try block");
try {
System.out.println("Entering second try block");
try {
throw new Ex();
} finally {
System.out.println("finally in 2nd try block");
}
} catch(Ex e) {
System.out.println("Caught Ex in first try block");
} finally {
System.out.println("finally in 1st try block");
}
}
}
2.
class FinallyClause{
public int methodA() {
try {
return 1;
}
catch (Exception e) { return 2; }
}
public int methodB() {
try {
return 3;
}
finally {
return 4;
}
}
}
public class ExerciseChp9_6_2 {
public static void main(String[] args) {
FinallyClause fc = new FinallyClause();
System.out.println("methodA returns " + fc.methodA());
System.out.println("methodB returns " + fc.methodB());
}
}
반응형
'전.java' 카테고리의 다른 글
스레드 (0) | 2021.02.14 |
---|---|
단정 (0) | 2021.02.14 |
도형 클래스 (Figure) (0) | 2021.02.09 |
큐 클래스 (Queue) (0) | 2021.02.09 |
점 연산자 사용 (0) | 2021.02.09 |