Skip to content

Commit

Permalink
add week11
Browse files Browse the repository at this point in the history
  • Loading branch information
Wave1994-Hoon committed Jul 10, 2021
1 parent e161e16 commit c80f636
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Item 70. 볡ꡬ할 수 μžˆλŠ” μƒν™©μ—λŠ” 검사 μ˜ˆμ™Έλ₯Ό, ν”„λ‘œκ·Έλž˜λ° 였λ₯˜μ—λŠ” λŸ°νƒ€μž„ μ˜ˆμ™Έλ₯Ό μ‚¬μš©ν•˜λΌ
## 1. 핡심 정리
- 검사 μ˜ˆμ™Έ: 볡ꡬ할 수 μžˆλŠ” 상황
- 비검사 μ˜ˆμ™Έ: ν”„λ‘œκ·Έλž˜λ° 였λ₯˜, ν˜Ήμ€ ν™•μ‹€ν•˜μ§€ μ•Šμ€ μΌ€μ΄μŠ€
- throwable: μ •μ˜ν•˜μ§€λ„ 말자
- 검사 μ˜ˆμ™ΈλΌλ©΄ 볡ꡬ에 ν•„μš”ν•œ 정보λ₯Ό μ•Œλ €μ£ΌλŠ” λ©”μ„œλ“œλ„ μ œκ³΅ν•˜μž

<br>

## 2. κ²€μ‹œ μ˜ˆμ™Έ (Checked Exception)
- ν˜ΈμΆœν•˜λŠ” μͺ½μ—μ„œ λ³΅κ΅¬ν•˜λ¦¬λΌ μ—¬κ²¨μ§€λŠ” 상황이라면 `검사 μ˜ˆμ™Έ`λ₯Ό μ‚¬μš©ν•˜λΌ.
- λ³΅κ΅¬ν•œλ‹€λŠ” 의미 ??
- ν˜ΈμΆœμžκ°€ μ˜ˆμ™Έλ₯Ό λ§ˆμ£Όμ³€μ„ λ•Œ, λŒ€μ‘ν•œλ‹€λŠ” 의미 κ°™λ‹€.


- ν˜ΈμΆœμžκ°€ κ·Έ μ˜ˆμ™Έλ₯Ό `catcb` 둜 μž‘μ•„ μ²˜λ¦¬ν•˜κ±°λ‚˜ 더 λ°”κΉ₯으둜 μ „νŒŒν•˜λ„λ‘ κ°•μ œν•˜κ²Œ λœλ‹€.


- API μ„€κ³„μžλŠ” API μ‚¬μš©μžμ—κ²Œ 검사 μ˜ˆμ™Έλ₯Ό λ˜μ Έμ£Όμ–΄ κ·Έ μƒν•­μ—μ„œ νšŒλ³΅ν•΄λ‚΄λΌκ³  μš”κ΅¬ν•œ 것이닀.


- ꡬ쑰 μ˜ˆμ‹œ
- Exception 의 μžμ‹ 클래슀 쀑 RuntimeException 을 μ œμ™Έν•œ λͺ¨λ“  ν΄λž˜μŠ€λŠ” CheckedException 이닀.

<br>

<img width="500" src="https://user-images.githubusercontent.com/60383031/125167279-af979880-e1da-11eb-8beb-1af60424045a.png">



- μ½”λ“œ μ˜ˆμ‹œ
```java
public class ObjectMapper extends ObjectCodec implements Versioned, Serializable {
// μ€‘λž΅

public void writeValue(DataOutput out, Object value) throws IOException {
this._writeValueAndClose(this.createGenerator(out), value);
}
}
```


<br>

## 3. 비검사 μ˜ˆμ™Έ (Unchecked Exception)
- 비검사 μ˜ˆμ™Έλž€ ?
- 일반적으둜 ν”„λ‘œκ·Έλž¨μ—μ„œ μž‘μ„ ν•„μš”κ°€ μ—†κ±°λ‚˜ ν˜Ήμ€ μž‘μ§€ 말아야 ν•œλ‹€.
- λͺ…μ‹œμ μΈ μ˜ˆμ™Έ 처리λ₯Ό κ°•μ œν•˜μ§€ μ•ŠλŠ” νŠΉμ§•μ΄ 있기 λ•Œλ¬Έμ— catch 둜 μž‘κ±°λ‚˜ throw 둜 ν˜ΈμΆœν•œ λ©”μ„œλ“œλ‘œ 에외λ₯Ό λ˜μ§€μ§€ μ•Šμ•„λ„ λœλ‹€.
- ꡬ쑰 μ˜ˆμ‹œ

<br>
<img width="500" src="https://user-images.githubusercontent.com/60383031/125167106-dc977b80-e1d9-11eb-8f3a-62891bdb19b0.png">

- λŸ°νƒ€μž„ μ—λŸ¬
- ν”„λ‘œκ·Έλž˜λ° 였λ₯˜λ₯Ό λ‚˜νƒ€λ‚Ό λ•ŒλŠ” λŸ°νƒ€μž„ μ˜ˆμ™Έλ₯Ό μ‚¬μš©ν•˜μž
- ν•΄λ‹Ή μ—λŸ¬λŠ” λŒ€λΆ€λΆ„ μ „μ œμ‘°κ±΄μ„ λ§Œμ‘±ν•˜μ§€ λͺ»ν–ˆμ„ λ•Œ λ°œμƒ
- μ „μ œμ‘°κ±΄ μ˜ˆμ‹œλ‘œλŠ” Index κ°€ μžˆλ‹€.
- Index λŠ” 0 to Array.size() - 1 사이에 μžˆμ–΄μ•Ό ν•œλ‹€. 이 μ „μ œμ‘°κ±΄μ΄ μœ„λ°°κ°€ λœλ‹€λ©΄ `ArrayIndexOfBoundsException` 이 λ°œμƒν•œλ‹€.

<br>

## 4. μ—λŸ¬ (Error)
- μ—λŸ¬ ???
- 보톡 JVM이 μžμ› λΆ€μ‘±, λΆˆλ³€μ‹ 깨짐 λ“± 더 이상 μˆ˜ν–‰μ„ 계속할 수 μ—†λŠ” 상황을 λ‚˜νƒ€λ‚Ό λ•Œ μ‚¬μš©ν•œλ‹€.
- Error λŠ” μ‹œμŠ€ν…œ λ ˆλ²¨μ—μ„œ μ‹¬κ°ν•œ μˆ˜μ€€μ΄κΈ° λ•Œλ¬Έμ— μ˜ˆμΈ‘ν•˜κ±°λ‚˜ μ²˜λ¦¬ν•  수 μžˆλŠ” 방법이 μ—†λ‹€.

- ꡬ쑰 μ˜ˆμ‹œ

<br>
<img width="500" src="https://user-images.githubusercontent.com/60383031/125167421-54b27100-e1db-11eb-9ab0-a0c6836e883d.png">

- 주의 사항
- Error λŠ” μƒμ†ν•˜μ§€ 말아야할 뿐 μ•„λ‹ˆλΌ, throw 문으둜 직접 λ˜μ§€λŠ” 일도 μ—†μ–΄μ•Ό ν•œλ‹€.

<br>

#### μ°Έκ³ 
- https://www.nextree.co.kr/p3239/
- https://cheese10yun.github.io/checked-exception/

0 comments on commit c80f636

Please sign in to comment.