Item 77. Exception Ignore
์์ธ๋ฅผ ๋ฌด์ํ์ง ๋ง๋ผ
๋ฉ์๋ ์ ์ธ์ ์์ธ๋ฅผ ๋ช
์ํ๋ฉด ํด๋น ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ๋ ์ ์ ํ ์กฐ์น๋ฅผ ์ทจํ ์ ์๋๋ก ๋์์ค๋ค.
์ด๋ฅผ ๋ฌด์ํ๋ ๋ฐฉ๋ฒ์ ๋งค์ฐ ๊ฐ๋จํ๋ฐ, try-catch
๋ธ๋ก์ ๋น์๋๋ ๊ฒ์ด๋ค.
class Example {
public static void main(String[] args) {
try {
// do something
} catch (Exception e) {
// ์๋ฌด๊ฒ๋ ํ์ง ์์
}
}
}
๋น์ฐํ๊ฒ๋ ๋ฌด์ํ๋ ๊ฒ์ ์ข์ง ์์๋ฐ, ๋ง์ฝ ์์ธ๋ฅผ ๋ฌด์ํ๊ณ ๋์ด๊ฐ์ผ ํ๋ค๋ฉด ์๋์ ๊ฐ์ด ์ฒ๋ฆฌํด์ฃผ๋ ๊ฒ์ด ์ข๋ค.
catch
๋ธ๋ก ์์ ์์ธ๋ฅผ ๋ฌด์ํ๋ ์ฃผ์์ ๋จ๊น์์ธ ๋ณ์ ์ด๋ฆ์
ignored
๋ก ๋ฐ๊ฟ
class Example {
public static void main(String[] args) {
try {
// do something
} catch (Exception ignored) {
// ~~์ ์ด์ ๋ก ์์ธ๋ฅผ ๋ฌด์ํจ
}
}
}
์์ธ ๋ฌด์๋ ๊ฒ์ฌ/๋น๊ฒ์ฌ ์์ธ ๋ชจ๋์ ํด๋น๋๋๋ฐ, ์ผ๋ฐ์ ์ผ๋ก ์์ธ๋ฅผ ๋ฌด์ํ๋ ๊ฒ์ด ์ข์ง ์์ผ๋ฏ๋ก ๊ฒ์ฌ ์์ธ๋ฅผ ๋ฌด์ํ๋ ๊ฒ์ ํน๋ณํ ์ด์ ๊ฐ ์์ ๋๋ง ํ์ฉํ๋ ๊ฒ์ด ์ข๋ค.
Last updated
Was this helpful?