๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/JAVA

[JAVA] Error, Checked Exception, Unchecked Exception ๋น„๊ต

by ynzu๐Ÿค 2022. 1. 12.
๋ฐ˜์‘ํ˜•


์ž๋ฐ”์—์„œ๋Š” ์˜ˆ์™ธ๋ฅผ ํฌ๊ฒŒ Error์™€ Exception์œผ๋กœ ๊ตฌ๋ถ„ํ•˜๊ณ , Exception์€ RuntimeException ์ƒ์† ์—ฌ๋ถ€์— ๋”ฐ๋ผ Checked Exception, Unchecked Exception์œผ๋กœ ๊ตฌ๋ถ„๋œ๋‹ค.

 

Error

์‹œ์Šคํ…œ์— ๋น„์ •์ƒ์ ์ธ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ๋กœ ์‹œ์Šคํ…œ ๋ ˆ๋ฒจ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์‹ฌ๊ฐํ•œ ์ˆ˜์ค€์˜ ์˜ค๋ฅ˜๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ, ๊ฐœ๋ฐœ์ž๊ฐ€ ์—์ธกํ•  ์ˆ˜ ์—†๊ธฐ์— ๋ฏธ๋ฆฌ Handlingํ•  ์ˆ˜ ์—†๋‹ค.


Exception

๊ฐœ๋ฐœ์ž๊ฐ€ ๊ตฌํ˜„ํ•œ ๋กœ์ง์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ฏธ๋ฆฌ ์˜ˆ์ธกํ•˜์—ฌ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์–ด์„œ ์ƒํ™ฉ์— ๋งž๊ฒŒ Handling ํ•ด์•ผํ•œ๋‹ค.

 

์•„๋ž˜๋Š” Checked Exception๊ณผ Unchecked Exception์„ ๋น„๊ตํ•œ ํ‘œ์ด๋‹ค.

  Checked Exception Unchecked Exception
๋กœ์ง์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ์—ฌ๋ถ€ ํ•„์ˆ˜
๋ฐ˜๋“œ์‹œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ์ฝ”๋“œ๊ฐ€ ์žˆ์–ด์•ผ ํ•จ
ํ•„์ˆ˜ X
์˜ˆ์™ธ ํ™•์ธ ์‹œ์  ์ปดํŒŒ์ผ ๋‹จ๊ณ„ ๋Ÿฐํƒ€์ž„ ์ค‘
์˜ˆ์™ธ ๋ฐœ์ƒ์‹œ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ Roll-backํ•˜์ง€ ์•Š์Œ Roll-back์ฒ˜๋ฆฌ ๋จ
์˜ˆ์‹œ(๋Œ€ํ‘œ์ ์ธ ํด๋ž˜์Šค) Exception์„ ์ƒ์†๋ฐ›๋Š” ํด๋ž˜์Šค ์ค‘
RuntimeException์„ ์ƒ์†๋ฐ›์ง€ ์•Š๋Š” ๋ชจ๋“  ์˜ˆ์™ธ ํด๋ž˜์Šค

ex) ClassNotFoundException, IOException, SQLException
RuntimeException์„ ์ƒ์†๋ฐ›๋Š” ๋ชจ๋“  ์˜ˆ์™ธ ํด๋ž˜์Šค

ex) NullPointerException, IndexOutOfBoundException

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€