본문 바로가기
IT-Language/IT-Java

java RuntimeException

by onfact 2023. 11. 5.

 

RuntimeException is a class in the Java programming language hierarchy used to handle exceptions that can occur at runtime, which are not checked by the compiler. These exceptions are part of the "Unchecked Exception" category, meaning that they do not require explicit handling using try-catch blocks or throws declarations, allowing the program to continue running even when such exceptions occur. However, it's important to exercise caution as these exceptions can indicate unexpected errors, and it's generally a good practice to handle or at least log them appropriately.

Here are some key RuntimeException classes and their descriptions:

ArithmeticException: Represents exceptions that occur during arithmetic operations, such as dividing an integer by zero.
NullPointerException: Occurs when attempting to access or manipulate an object that is null.
ArrayIndexOutOfBoundsException: Happens when attempting to access an array element using an invalid index.
IllegalArgumentException: Thrown when an illegal argument is passed to a method.
IllegalStateException: Signifies that the object is in an inappropriate state when a method is called.
ClassCastException: Occurs when an inappropriate type casting operation is attempted.
IndexOutOfBoundsException: Covers situations where the index used to access a collection or string is out of bounds.
NumberFormatException: Raised when parsing a string to a numeric type, but the string does not have the appropriate format.
RuntimeException and its subclasses are mainly used to handle logic errors in a developer's code or unexpected data conditions that may arise at runtime. Handling these exceptions or at least logging them can help improve the robustness of your program, ensuring that it continues to operate in the face of unexpected circumstances.

'IT-Language > IT-Java' 카테고리의 다른 글

JAVA - AOP (관점지향 프로그래밍)  (0) 2024.04.10
어노테이션(Annotation) - @Target  (0) 2023.11.30
어노테이션(Annotation) - @Retention  (0) 2023.11.30
JAVA17 - switch  (0) 2023.11.05
Java와 VC++ 동기화 비교  (0) 2023.11.05