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

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Java] Collapse 'catch' blocks

์‹œ์ž‘

Lint ๊ฒฝ๊ณ ์— ๋Œ€์‘ํ•˜๋ฉด์„œ ๊ธฐ์กด try - catch ๋ฌธ์—์„œ ๋‹ค๋ฅธ exception๋„ catch ๋ฌธ์— ๋„ฃ๊ฒŒ ๋˜์—ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ IDE์—์„œ Collapse 'catch' blocks ๋ผ๋ฉฐ catch ๋ฌธ์— ๋ฌด์–ธ๊ฐ€ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๋ ค์คฌ๋‹ค.

 

๋‘ catch ๋ฌธ ๋ธ”๋Ÿญ์˜ ๋‚ด์šฉ์ด ๊ฐ™๊ธฐ๋Š” ํ–ˆ๋‹ค.

 

IDE์˜ ์ž‘์—… ํ›„

๊ฒฐ๊ณผ. ํ•œ catch ๋ฌธ ๋ธ”๋Ÿญ์œผ๋กœ ํ•ฉ์ณ์กŒ๋‹ค.

์—๋Ÿฌ ์ฒ˜๋ฆฌ ๋กœ์ง์ด ๊ฐ™์€ ๋‘ catch ๋ฌธ ๋ธ”๋Ÿญ์„ ํ•˜๋‚˜๋กœ ์“ธ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑธ ์•Œ์•˜๋‹ค. 

 

Collapse ์˜๋ฏธ

Collapse 'catch' blocks์˜ 'collapse' ์˜๋ฏธ๋ฅผ ์ฐพ์•„๋ดค๋‹ค.

 

https://en.dict.naver.com/#/entry/enko/e0708beb85ad4906a123396e1c971bee

 

๋„ค์ด๋ฒ„ ์˜์–ด์‚ฌ์ „

๋ฏธ๊ตญ/์˜๊ตญ์‹ ๋ฐœ์Œ, ์—ฌ๋Ÿฌ ์ข…๋ฅ˜์˜ ์ถœํŒ์‚ฌ ์‚ฌ์ „ ๋œปํ’€์ด, ํ’๋ถ€ํ•œ ์œ ์˜์–ด/๋ฐ˜์˜์–ด, ๋Œ€ํ‘œ์‚ฌ์ „ ์„ค์ • ๊ธฐ๋Šฅ, ์ƒ์„ธ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ, ์˜์–ด ๋‹จ์–ด์žฅ ์ œ๊ณต

en.dict.naver.com

 

๋„ค์ด๋ฒ„ ์‚ฌ์ „์—์„œ ๋™์•„์ถœํŒ ๋ฒ„์ „์˜ ํ•ด๋‹น ๋œป์ด ๊ฐ€์žฅ ์ ์ ˆํ•œ ๊ฒƒ ๊ฐ™๋‹ค.

 

๋„ค์ด๋ฒ„ ์‚ฌ์ „- collpase ๋‹จ์–ด ๋œป. ๋™์•„์ถœํŒ ๋ฒ„์ „. ํƒ€๋™์‚ฌ ๋œป.

 

Kotlin์„ ์ฆ๊ฒจ์จ์„œ Java์™€๋Š” ๊ฑฐ๋ฆฌ๊ฐ€ ๋ฉ€์–ด์ง€๊ธฐ๋Š” ํ–ˆ๋Š”๋ฐ, ์ด๋Ÿฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ์ถ•์•ฝ ๊ธฐ๋Šฅ์ด ์žˆ๋Š”์ง€ ์ด์ œ ์•Œ์•˜๋‹ค.

 

๊ตฌ๊ธ€๋งํ•ด์„œ ์ฐพ์€ ์Šคํƒ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ๊ธ€

https://stackoverflow.com/a/11211334

 

Is it possible in Java to catch two exceptions in the same catch block?

I need to catch two exceptions because they require the same handling logic. I would like to do something like: catch (Exception e, ExtendsRuntimeException re) { // common logic to handle both

stackoverflow.com

Java 7๋ถ€ํ„ฐ Multiple-excpetion catch ๊ธฐ๋Šฅ์„ ์ง€์›ํ–ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

 

Java์˜ Exception catch ๋ธ”๋ก ๊ธ€

https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html

 

The catch Blocks (The Java™ Tutorials > Essential Java Classes > Exceptions)

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated

docs.oracle.com

Java 7 ์ดํ›„๋ถ€ํ„ฐ, ํ•˜๋‚˜์˜ catch ๋ธ”๋ก์œผ๋กœ ํ•˜๋‚˜ ์ด์ƒ์˜ Exception๋“ค๋กœ ๋™์ผํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. '|' ์š” ์„ธ๋กœ ๋ฐ”๋ฅผ ์จ์„œ Exception๋“ค์„ ๊ตฌ๋ถ„ํ•œ๋‹ค๊ณ .

 

Java7์˜ Exception ์ฒ˜๋ฆฌ ๊ธ€

https://www.oracle.com/technical-resources/articles/java/java7exceptions.html

 

Working with Java SE 7 Exception Changes

Learn how to take advantage of improved exception handling, one of many useful small language changes found in Project Coin, in Java SE 7. Downloads: Introduction In this article, we cover some changes are a part of the Java Platform, Standard Edition 7 (J

www.oracle.com

Multi-Catch Exceptions ์ฒ˜๋ฆฌ ์™ธ์— Rethrow Exceptions, Try-with-Resource์— ๋Œ€ํ•ด ์„ค๋ช…ํ•œ ๊ธ€์ด๋‹ค.

 

 

Mutli-Catch Exceptions

๋‹ค๋ฅธ Exeption๋“ค์ด ๋™์ผํ•œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผํ•  ๋•Œ ์‚ฌ์šฉ. ๋ณด์ผ๋Ÿฌ ์ฝ”๋“œ๊ฐ€ ์ค€๋‹ค.

 

Rethrow Exceptions

catch ๋ธ”๋Ÿญ ์•ˆ์— ๋“ค์–ด์™€์„œ ์ถ”์ ํ•œ exception์„ ๋‹ค์‹œ throwํ•ด์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฒ• ์„ค๋ช…. ์˜ˆ์ œ ์ฝ”๋“œ ํ™•์ธ ํ•„์š”.

 

Try-with-Resource

try ๋ฌธ ์•ˆ์—์„œ ๋ฆฌ์†Œ์Šค๋ฅผ openํ•˜๊ณ , finally ๋ฆฌ์†Œ์Šค๋ฅผ closeํ•  ๋•Œ, finally ์•ˆ์—์„œ ๋˜ try-catch ๋ฌธ์„ ์จ์•ผ ํ•  ๋•Œ ์‚ฌ์šฉ. ๋ณด์ผ๋Ÿฌ ์ฝ”๋“œ๊ฐ€ ์ค€๋‹ค. ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ํ™•์ธ ํ•„์š”.