크게 다음과 같이 분류된다.
Throwable
을 상속받으므로 예외 처리가 가능은 하지만 잘 안 함예외는 다시 일반 예외(exception)과 실행 예외(runtime exception)로 나뉜다.
try-catch
등)가 없다면 컴파일 오류가 발생한다. java.lang.Exception
클래스를 상속한다.java.lang.Exception
클래스를 바로 상속하고, Runtime exception 클래스는 java.lang.RuntimeException
클래스를 상속한다.java.lang.RuntimeException
클래스는 java.lang.Exception
클래스를 상속한다.ClassNotFoundException
InterruptedException
NullPointerException
ArrayIndexOutOfBoundsException
NumberFormatException
ClassCastException
ClassCastException
이 발생한다.ArithmeticException
ArithmeticException
/**
* A constant holding the positive infinity of type
* {@code double}. It is equal to the value returned by
* {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
*/
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
/**
* A constant holding the negative infinity of type
* {@code double}. It is equal to the value returned by
* {@code Double.longBitsToDouble(0xfff0000000000000L)}.
*/
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
/**
* A constant holding a Not-a-Number (NaN) value of type
* {@code double}. It is equivalent to the value returned by
* {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
*/
public static final double NaN = 0.0d / 0.0;
Double
클래스 맨 첫 부분이다.
정수를 0으로 나누는 경우(3/0
등)에는 ArithmeticException
이 발생하지만 정수에서는 그냥 Infinity
로 출력된다.
NaN
은 Not a Number
라는 뜻으로 음수의 제곱근 등을 말한다.
System.out.println(Math.sqrt(-1));
System.out.println(3.0/0);
즉 위 코드의 출력은 다음과 같다.
NaN
Infinity