Exception — 예외
Exception — 예외
Exception 클래스와 그 하위 클래스는 합리적인 애플리케이션이 잡고 싶어할 수 있는 조건을 나타내는 Throwable의 한 형태입니다. Exception 클래스와 RuntimeException의 하위 클래스가 아닌 모든 하위 클래스는 체크 예외(checked exception)입니다.
본문
체크 예외는 메서드나 생성자의 실행 중 던져질 수 있고 해당 경계 밖으로 전파될 수 있다면 메서드나 생성자의 throws 절에 선언되어야 합니다.
public class Exception extends Throwable
생성자
public Exception()
public Exception(String message)
public Exception(String message, Throwable cause)
public Exception(Throwable cause)
protected Exception(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
- 기본 생성자는 상세 메시지 없이 예외를 만듭니다.
String message생성자는 상세 메시지를 지정합니다.String message, Throwable cause생성자는 메시지와 원인을 지정합니다.- 마지막 protected 생성자는 억제(suppression) 활성화 여부와 스택 트레이스 기록 가능 여부를 추가로 지정합니다.
체크 예외는 컴파일러가 반드시 처리하거나 선언하도록 강제하므로, 입출력·네트워크 등 실패 가능성이 있는 연산에서 자주 사용됩니다.