๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš— Major Study (Bachelor)/๐ŸŸ  JAVA Programming

JAVA ํ”„๋กœ๊ทธ๋ž˜๋ฐ 9.3

by UKHYUN22 2021. 11. 2.
728x90

์ฑ…์ž„์„ ์ „๊ฐ€ํ•˜๋Š” ๋ฒ• (Passing the buck)

 

responsiblility, handle any exception

 

๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์— ์ฑ…์ž„์„ ์ „๊ฐ€ํ•˜๋Š” ๊ฒƒ. ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด catch๋ฅผ ํ•ด์•ผํ•˜๋Š”๋ฐ ํ•˜์ง€ ๋ชปํ•˜๋ฉด ๊ทธ๊ฒƒ์— ๋Œ€ํ•œ ์ฑ…์ž„์„ ์œ„์—๋‹ค ์ „๊ฐ€์‹œํ‚ค๋Š” ๊ฒƒ์ด๋‹ค.

throws์˜ ๋œป์€, ๋„ˆ๊ฐ€ ๋‚˜๋ฅผ ๋ถ€๋ฅธ๋‹ค๋ฉด ๋ฐ˜๋“œ์‹œ exception์„ handle ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

 

 

 

a-throws clause

 

normal ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ณณ์—์„œ throws๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  try-catch๋ฌธ์„ ํ†ตํ•ด์„œ exception์„ handle ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด normal() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ ๊ณณ์—์„œ ์ฑ…์ž„์„ ์ ธ๋ผ!!! ๋ผ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ€์ง„๋‹ค

 

 

์ด ๊ฒฝ์šฐ์—๋Š” ์ปดํŒŒ์ผ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. normal ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์—์„œ๋„ try-catch๋กœ handleํ•˜์ง€ ๋ชปํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

 

must be caught or declared

 

 

 

in a catch block, in a throws clause

 

 

 

later, specific

 

์—ฌ๋Ÿฌ ๊ฐœ์˜ Exception์ด ์กด์žฌํ•˜๋ฉด general ํ•œ Exception์„ ๋‚˜์ค‘์— ๋‹ค๋ฃฌ๋‹ค

child exception์„ ๋จผ์ € ์ฒ˜๋ฆฌํ•˜๊ณ  parent exception์„ ๋‚˜์ค‘์— ์ฒ˜๋ฆฌํ•œ๋‹ค.

ํ•˜์ง€๋งŒ ๊ฐ™์€ ์„œ์—ด์˜ Exception๋ผ๋ฆฌ๋Š” ์ˆœ์„œ๊ฐ€ ์ƒ๊ด€์ด ์—†๋‹ค.

 

 

completeness, whether or not

 

๋ฐ˜๋“œ์‹œ ์ˆ˜ํ–‰๋˜๋Š” ๋ฌธ์žฅ