File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,34 @@ throw 경로에 위치하는 모든 함수가 최하위 함수에서 던지는
111111| 처리 여부 | 반드시 처리 | 명시적으로 처리하지 않아도 됨 |
112112| 트랜잭션 처리 | roll-back 하지 않음 | roll-back 함 |
113113| 예시 | IOException, ClassNotFoundException | NullPointerException, ArithmeticException |
114+ 아래 코드는 단순한 출력을 하는 메소드이다.
115+ ```
116+ public void printA(bool flag) {
117+ if(flag)
118+ System.out.println("called");
119+ }
120+
121+ public void func(bool flag) {
122+ printA(flag);
123+ }
124+
125+ ```
126+ 문득 프린트를 안할 때 NotPrintException 을 던지기로 구현을 변경했을 때
127+ ```
128+ public void printA(bool flag) throws NotPrintException {
129+ if(flag)
130+ System.out.println("called");
131+ else
132+ throw new NotPrintException();
133+ }
134+
135+ public void func(bool flag) throws NotPrintException {
136+ printA(flag);
137+ }
138+ ```
139+ 해당 함수 뿐만이 아니라 호출하는 함수도 수정을 해줘야 하기 때문에 OCP 를 위반하게 된다.
140+
141+
114142
115143## 4. 예외에 의미를 제공하라
116144예외에 정보를 충분히 담아서 던지면, 오류가 발생한 원인과 위치를 찾기 쉬워진다.
You can’t perform that action at this time.
0 commit comments