#멋쟁이사자처럼 #부트캠프 #백엔드 #JAVA

실습 문제

URLs to Check

RuntimeException VS Exception

public class Main {
    public static void methodA() throws RuntimeException {

    }

    public static void methodB() throws Exception {

    }

    public static void main(String[] args) {
        methodA();
        methodB(); // Unhandled exception: java. lang. Exception
    }
}

Automatic Resource Management

Example1

FileInputStream fis = null;
try {
    fis = new FileInputStream("abc");
} catch (Exception e) {
    System.out.println(e);
} finally {
    try {
        fis.close();
    } catch (IOException e) {
        System.out.println(e);
    }
}

Example2

try (FileInputStream fis2 = new FileInputStream("abc")) {
    // ...
} catch (Exception e) {
    System.out.println(e);
}