[JAVA] Throwable (Error, Exception)

[JAVA] Throwable (Error, Exception)

Last modified on 2025-04-18 , by hjjae2

Throwable #

" The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in a catch clause. For the purposes of compile-time checking of exceptions, Throwable and any subclass of Throwable that is not also a subclass of either RuntimeException or Error are regarded as checked exceptions. “

  1. 였직 Throwable, Throwable 의 ν•˜μœ„ 클래슀만 JVM, Java 에 μ˜ν•΄ 던져질 수 있음 (can be thrown)

  2. 였직 Throwable, Throwable 의 ν•˜μœ„ 클래슀만 catch 문법에 μ‚¬μš©λ  수 있음

  3. Error, RuntimeException 을 μ œμ™Έν•œ Throwable 의 ν•˜μœ„ν΄λž˜μŠ€λŠ” CheckedException

  • CheckedException : 컴파일 μ‹œμ μ— Exception 체킹 λͺ©μ μœΌλ‘œ μ‚¬μš©λ¨

  • class μž„μ— 주의 (μ°Έκ³  : why is java.lang.Throwable a class?)

public class Throwable implements Serializable {
    ...
}

Error #

μ‹œμŠ€ν…œ(μ„œλ²„) 레벨, HW 레벨의 였λ₯˜

μˆ˜μŠ΅ν•  수 μ—†λŠ” μ‹¬κ°ν•œ 문제

  • VirtualMachineError
  • OutOfMemoryError
  • InternalError
  • StackOverflowError
  • UnknownError

Exception #

CheckedException #

μ˜ˆμ™Έ 처리 ν•„μˆ˜

컴파일 μ‹œ 체크

  • IOException
  • InterruptedException
  • ClassNotFoundException
  • NoSuchMethodException
  • NoSuchFieldException

RuntimeException (UncheckedException) #

  • NullPointerException
  • ArithmeticException
  • IllegalArgumentException
  • NumberFormatException