Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- CSS
- Algorithm
- data structure
- MIPS
- while
- MacOS
- php
- Pipelining
- DoM
- html
- python
- Java
- web
- DATAPATH
- computer
- react
- DB
- function
- DS
- architecture
- javascript
- for
- Class
- instruction
- system
- XML
- Linux
- mysql
- github
- control
Archives
- Today
- Total
YYYEJI
[JAVA] 예외처리(throws)란? 본문
728x90
throws란?
자신을 호출하는 메소드에 예외처리의 책임을 떠넘기는 것입니다.
throws 예제 코드입니다.
public static void main(String[] args) {
try {
divideByZeroTest(20, 0);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException: " + e.getMessage());
}
}
public static void divideByZeroTest(int a, int b) throws ArithmeticException{
System.out.println("The result is "+ a/b + ".");
}
- throws는 throw와 다르게 예외선언을 따로 하지 않아도 됩니다.
divideByZeroTest 메소드(method)에 예외처리의 책임을 넘겼기 때문입니다.
- divideByZeroTest 메소드(method)를 정의할 때 throws ArithmeticException 코드를 작성하면 됩니다.
◡̈
'Java' 카테고리의 다른 글
[JAVA] 예외처리(try-catch, throw, finally)란? (0) | 2022.12.27 |
---|---|
[JAVA] 추상 클래스(Abstract Class)란? (0) | 2022.12.27 |
[JAVA] 인터페이스(Interface)란? (0) | 2022.12.27 |
[JAVA] 오버라이딩(Overriding)이란? (0) | 2022.12.27 |
[JAVA] Super 메소드 (0) | 2022.12.27 |