๐ป
Java ํ๋ก๊ทธ๋๋ฐ - ์์ธ์ฒ๋ฆฌ(Exception) ๋ณธ๋ฌธ
์๋์ ์์๋ฅผ ๋ณด๋ฉด ๋ณ๊ฑฐ ์๋ ์ฝ๋์ด์ง๋ง, ์ค๋ฅ๊ฐ ๋ ๋ถ๋ถ๋ค์ด ๋ง๋ค.
์ ๋ ฅ๋ฐ์ ์๊ฐ ์ ์ํ์ด ์๋๊ฒฝ์ฐ, ๋๋๋ ์๊ฐ 0์ผ ๊ฒฝ์ฐ ๋ฑ๋ฑ
์์ธ ์ฒ๋ฆฌ
์์ 1)
0์ผ๋ก ๋๋๋์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์.
ArithmeticException
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/ArithmeticException.html
ArithmeticException (Java SE 14 & JDK 14)
All Implemented Interfaces: Serializable public class ArithmeticException extends RuntimeException Since: 1.0 See Also: Serialized Form Constructor Summary Constructors Constructor Description ArithmeticException() Constructs an ArithmeticException with
docs.oracle.com
NumberFormatException
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/NumberFormatException.html
NumberFormatException (Java SE 14 & JDK 14)
All Implemented Interfaces: Serializable public class NumberFormatException extends IllegalArgumentException Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the approp
docs.oracle.com
์์ 2)
์์ 3) ์์ธ์ฒ๋ฆฌ๋ ์๋์ง๋ง ๋ค์ ์์ ๋ฅผ ์ค์ตํด๋ณด์.
args์ ๋ ฅํ๋ ๋ฐฉ๋ฒ
์ค๋ฅธ์ชฝ ๋ง์ฐ์ค > run > run configuration > arguments์ ์ํ๋ ๋ฐ์ดํฐ ๋ฃ๊ณ > run ํด๋ฆญ
๋ฐ์ดํฐ๊ฐ 2๊ฐ๊ฐ ํ์ํ๋ฐ, 2๊ฐ๋ณด๋ค ํฐ๊ฒฝ์ฐ๋ ์๊ด์์ง๋ง ๋ถ์กฑํ ๊ฒฝ์ฐ ERROR ๊ฐ ์๊ธด๋ค.
์์ 4)
NullPointerException
: ์๋ฐ์์ ๊ฐ์ฅ ๋ง์ด ์๊ธฐ๋ ์๋ฌ
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/NullPointerException.html
NullPointerException (Java SE 14 & JDK 14)
All Implemented Interfaces: Serializable public class NullPointerException extends RuntimeException Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of a null object. Accessin
docs.oracle.com
์์ 5)
ClassCastException
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/ClassCastException.html
ClassCastException (Java SE 14 & JDK 14)
All Implemented Interfaces: Serializable public class ClassCastException extends RuntimeException Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a Cla
docs.oracle.com
์์ 6)
InputMismatchException
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/InputMismatchException.html
InputMismatchException (Java SE 14 & JDK 14)
All Implemented Interfaces: Serializable public class InputMismatchException extends NoSuchElementException Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the
docs.oracle.com
์์ 7)
์์ 8)
๋ค์ค catch๋ฌธ์ ์ฌ์ฉํด์ ๋ค์ํ ์ข ๋ฅ์ ์์ธ๋ฅผ ์ฒ๋ฆฌํ๋ค.
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
์์ธํด๋์ค๋ ๊ฑฐ์ ๋๋ถ๋ถ ์์ 3๊ฐ์ง๋ฅผ ์์ํด๋์ค๋ก ๊ฐ์ง๊ณ ์์ด์ ์์ํด๋์ค๋ฅผ ์ด์ฉํด์ ๋ค์์ ์์ธ๋ฅผ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ๊ฐ๋ฅํ์ง๋ง ํ๋ก๊ทธ๋จ ๋ก์ง์ ๋ํ ์ผํ๊ฒ ๋๋ ์ผํ ๋(์: ๋ก๊ทธ์ธ ์ ์์ด๋์ฒ๋ฆฌ, ํจ์ค์๋ ์ฒ๋ฆฌ) ์๋ ๋ฐ๋ก ์ฒ๋ฆฌ๋ฅผ ํด์ค์ผํ๋ค. ๋ํ ์ผํ๊ฒ ์ฌ์ฉ์ ๋ฉ์ธ์ง๋ฅผ ๋ค๋ฅด๊ฒ ํ๊ณ ์ถ์ ๋๋ ๋ฐ๋ก ์ฒ๋ฆฌํด์ค์ผํ๋ค.
์์ธ ๋ฐ์
: ์ปดํ์ผ ์ ์ฅ์์๋ ์๋ฌ๊ฐ ์๋์ง๋ง, ๋ด ํ๋ก๊ทธ๋จ์์์๋ ์๋ฌ(์๋ฅผ๋ค๋ฉด, ์ํ๊ณ์ข ๊ฐ์ ๊ฒฝ์ฐ -๋ฅผ ๋นผ๊ณ ์ ๋ ฅํ๋ผ๊ณ ํ๋ ๊ฒ์ฒ๋ผ)
์์ 10)
์์ธ ์ ๊ฐ
'KITRI > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Java ํ๋ก๊ทธ๋๋ฐ - ์ค๋ ๋(Thread) (0) | 2020.05.20 |
---|---|
Java ํ๋ก๊ทธ๋๋ฐ - byte ์ ์ถ๋ ฅ, char์ ์ถ๋ ฅ (0) | 2020.05.20 |
Java ํ๋ก๊ทธ๋๋ฐ - MVC ํจํด (0) | 2020.05.15 |
Java ํ๋ก๊ทธ๋๋ฐ - ์ปฌ๋ ์ ํ๋ ์์ํฌ(List, Set, Map) (0) | 2020.05.14 |
Java ํ๋ก๊ทธ๋๋ฐ - [๊ธฐ๋ณธ API ํด๋์ค] Format ํด๋์ค(DecimalFormat, SimpleDateFormat) (0) | 2020.05.14 |