JAVA/EXCEPTION
java.lang.Exception type
hi-admin
2023. 7. 21. 21:39
java.lang.Exception is a class in the Java programming language that represents a general exception. It is the superclass of all checked exceptions, which means any exception that is a subclass of Exception must be either caught using a try-catch block or declared in the method's signature using the throws keyword.
Here are some commonly used subclasses of java.lang.Exception:
- ArithmeticException: This exception is thrown when an arithmetic operation (such as division by zero) causes an error.
- NullPointerException: This exception is thrown when attempting to access or manipulate an object that is null.
- ArrayIndexOutOfBoundsException: This exception is thrown when attempting to access an array with an invalid index (e.g., an index that is negative or greater than the array length).
- IllegalArgumentException: This exception is thrown when an inappropriate argument is passed to a method.
- InterruptedException: This exception is thrown when a thread is waiting, sleeping, or otherwise occupied, and it is interrupted.
- NumberFormatException: This exception is thrown when trying to convert a string to a numeric type, but the string does not have the appropriate format for the conversion.
- ClassNotFoundException: This exception is thrown when trying to load a class using Class.forName() but the specified class cannot be found.
- IOException: This is a general exception class for I/O operations that can occur during reading from or writing to streams, files, etc.
- SQLException: This exception is used for database-related errors when working with JDBC (Java Database Connectivity).
- FileNotFoundException: This exception is thrown when attempting to access a file that does not exist.
Remember that exceptions should be handled appropriately in your code to provide meaningful error messages to users or developers and to prevent unexpected program termination.