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:

  1. ArithmeticException: This exception is thrown when an arithmetic operation (such as division by zero) causes an error.
  2. NullPointerException: This exception is thrown when attempting to access or manipulate an object that is null.
  3. 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).
  4. IllegalArgumentException: This exception is thrown when an inappropriate argument is passed to a method.
  5. InterruptedException: This exception is thrown when a thread is waiting, sleeping, or otherwise occupied, and it is interrupted.
  6. 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.
  7. ClassNotFoundException: This exception is thrown when trying to load a class using Class.forName() but the specified class cannot be found.
  8. IOException: This is a general exception class for I/O operations that can occur during reading from or writing to streams, files, etc.
  9. SQLException: This exception is used for database-related errors when working with JDBC (Java Database Connectivity).
  10. 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.