์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- Publishing
- ๋ฐฑ์ค์๊ณ ๋ฆฌ์ฆ
- testing
- ๋ถํธ์บ ํ
- CLI๋ช ๋ น์ด
- ์๋ฐ
- ์๊ณ ๋ฆฌ์ฆ
- ์ปฌ๋ ์ ํ๋ ์์ํฌ
- ์ธํ ๋ฆฌ์ ์ด
- ๋ฌธ์์ด๋ค์ง๊ธฐ
- ๊ณ์ฐ๊ธฐ๋ง๋ค๊ธฐ
- Spring Security
- fibonacci
- ์คํ๋ง
- ์ ๋ค๋ฆญ์ค
- ๋ฐ์ผ๋ฆฌ์ฝ๋ฉ
- spring data jpa
- HTML
- ๊ทธ๋ฆฌ๋
- CSS
- ํ์ดํ๋ก๊ทธ๋๋ฐ
- ํ๊ณ
- Spring Data JDBC
- ๊นํ๋ธ
- ๋ฐฑ์๋
- java
- FilterChain
- ์๋ฃ๊ตฌ์กฐ
- ์ฒซ๊ธ์๋๋ฌธ์
- ๊ฑฐ๋ญ์ ๊ณฑ
Archives
- Today
- Total
๋์ ๋ชจ์
045 | Checked / Unchecked / Customised Exception ๋ณธ๋ฌธ
๐Checked Exception
- ์์ธ๋ฅผ ์ก์์(catch) ์ฒดํฌํ ํ ๋ฐ๋์ ์๋ฌ์ฒ๋ฆฌ(try~catch)๋ฅผ ํด์ผํ๋ ์์ธ์ด๋ค.
- Exception ํด๋์ค์ ํ์ ํด๋์ค (Exception ์์๋ฐ์)
- ClassNotFoundException, FileNotFoundException, SQLException, …
๐Unchecked Exception
- ์์ธ๋ฅผ ์ก์์(catch) ํด๋น ์์ธ์ ๋ํ ์ฒ๋ฆฌ(try~catch)๋ฅผ ํ ํ์๊ฐ ์๋ ์์ธ์ด๋ค.
- RuntimeException์ ํ์ ํด๋์ค (RuntimeException ์์๋ฐ์)
- ์ฃผ๋ก ๊ฐ๋ฐ์๊ฐ ์ฝ๋๋ฅผ ์๋ชป ์์ฑํด์ ๋ฐ์ํ๋ ์ค๋ฅ๋ค์ ๋ชจ๋ RuntimeException์ ์์ํ ์์ธ๋ค์ด๋ค.
- NullPointException, ArrayIndexOutOfBoundsException, …
๐Custom Exception
- ๊ธฐ์กด ์์ธ ํด๋์ค ์ธ์ RuntimeException / Exception์ ์์ํด์ ์๋ก์ด ์์ธ ํด๋์ค๋ฅผ ์ง์ ๋ง๋ค์ด์ ์ฌ์ฉํ ์ ์๋ค.
- ์ฌ์ฉ์ ์ ์ ์์ธ๋ก ์๋น์ค ๊ณ์ธต์ ๋น์ฆ๋์ค ๋ก์ง์์ ๋ฐ์ํ๋ ๋ค์ํ ์์ธ๋ฅผ ๋์ง ์ ์๊ณ , ๋์ ธ์ง ์์ธ๋ Exception Advice์์ ์ฒ๋ฆฌํ ์ ์๋ค.
๐Exception Handling
- ์์ธ ์ฒ๋ฆฌ: ํ๋ก๊ทธ๋จ ์คํ ์ ๋ฐ์ํ ์ ์๋ ์์ธ ์ํฉ์ ๋๋นํด ์คํ์ค์ธ ํ๋ก๊ทธ๋จ์ ์ํ๋ฅผ ์ ์งํด์ฃผ๋ ๊ฒ
๐งฉ throw / catch on purpose from programmer
- ๋ฐฑ์๋ ์๋ฒ์ ์ธ๋ถ ์์คํ
๊ณผ์ ์ฐ๋์์ ๋ฐ์ํ๋ ์๋ฌ ์ฒ๋ฆฌ
- ๋ฐฑ์๋ ์๋ฒ ์ชฝ์์ ์์ธ๋ฅผ ์๋์ ์ผ๋ก ๋์ ธ์ ํด๋ผ์ด์ธํธ ์ชฝ์ ์๋ฌ๊ฐ ๋ฐ์ํ ์ ๋ณด๋ฅผ ์๋ ค์ค ์ ์๋ค.
- ์กฐํํ๋ ค๋ ๋ฆฌ์์ค(์์, Resource)๊ฐ ์์คํ
๋ด๋ถ์ ์๋ ๊ฒฝ์ฐ
- ์๋์ ์ผ๋ก ์๋น์ค ๊ณ์ธต์์ ํด๋ผ์ด์ธํธ ์ชฝ์ ํด๋น ์ ๋ณด๊ฐ ์๋ค๋ ์์ธ๋ฅผ ์ ์กํด์ ์๋ ค์ค ์ ์๋ค.
๐งฉ throw / catch on purpose
- throw ํค์๋๋ฅผ ์ฌ์ฉํด์ ์์ธ๋ฅผ ๋ฉ์๋ ๋ฐ๊นฅ์ผ๋ก ๋์ง ์ ์๋ค. ๋์ ธ์ง ์์ธ๋ ๋ฉ์๋ ๋ฐ๊นฅ์ธ ๋ฉ์๋๋ฅผ ํธ์ถํ ์ง์ ์ผ๋ก ๋์ ธ์ง๋ค.
- ์๋ฅผ ๋ค์ด Service Layer์์ ๋์ง ์์ธ๋ API Layer์ Handler Method๋ฅผ ์ด์ฉ ์ค์ธ Controller๊ฐ ๋ฐ์์ ์ฒ๋ฆฌํ๋ค.
๐ฌ about Business Exception
ํ์ต ์ฝํ ์ธ ์ ๋น์ฆ๋์ค์ ์ธ ์์ธ์ ๋ป์ด ์ ์๋ฟ์ง ์์์ ์ฐพ์๋ณด์๋๋ฐ ๊ทธ๋ฐ๊ฑด ์๋ค๊ณ ... ??
์๋ฐ์์ ์์ธ๋ Checked(inherited from Exception) / Unchecked(inherited from RuntimeException) ๋ ์ค ํ๋์ด๋ค.
๊ตฌ๊ธ๋งํ ๊ฒฐ๊ณผ์ ๋ฐ๋ฅด๋ฉด '๋น์ฆ๋์ค ์์ธ'๋ผ๋ ์ฉ์ด๋ ์ํฉ์ ๋ฐ๋ผ ๋ค๋ฅธ๋ฐ, ๋ด๋ถ API๋ฅผ ์ฒ๋ฆฌํ ๋ ์๋ชป๋ ๋ด์ฉ์ ๋น์ฆ๋์ค ์์ธ๋ก ํฌ์ฅํ๊ฑฐ๋, ํ์ํ ์ํฉ์์ ์์ฒด ์ ์ํ๋ '๋น์ฆ๋์ค'๋ผ๋ ์์ธ๋ฅผ ๋ง๋ค๊ฑฐ๋. ์ด๋ฐ ์์ผ๋ก ์ฌ์ฉ๋๋ ๊ฒ ๊ฐ๋ค!
'SEB > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
052 | Transaction (0) | 2022.09.05 |
---|---|
046 | Spring Data JDBC (0) | 2022.08.26 |
044 | Exception Handling in Spring MVC (0) | 2022.08.24 |
043 | Layer interconnect & Class Mapping (0) | 2022.08.23 |
042 | DTO ์ ํจ์ฑ ๊ฒ์ฆ (0) | 2022.08.23 |
Comments