0% found this document useful (0 votes)
17 views1 page

Exception Types

Java provides predefined exception classes to handle errors that may occur in programs. Some common predefined exceptions include ArithmeticException for division by zero, NullPointerException for null object references, and ArrayIndexOutOfBoundsException for invalid array indexes. There are also exceptions for illegal arguments, file not found errors, and interrupted threads. Java exceptions make it easier for programs to handle errors in a robust manner.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
17 views1 page

Exception Types

Java provides predefined exception classes to handle errors that may occur in programs. Some common predefined exceptions include ArithmeticException for division by zero, NullPointerException for null object references, and ArrayIndexOutOfBoundsException for invalid array indexes. There are also exceptions for illegal arguments, file not found errors, and interrupted threads. Java exceptions make it easier for programs to handle errors in a robust manner.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

TYPES OF EXCEPTIONS IN JAVA

Java provides a wide range of predefined exception classes to cover various error scenarios
that might occur in your programs. Here are some of the commonly used predefined
exception classes in Java:

1. ArithmeticException: Thrown when an arithmetic operation results in an error, such


as division by zero.
2. NullPointerException: Thrown when you try to access or manipulate an object that
is null.
3. ArrayIndexOutOfBoundsException: Thrown when you attempt to access an array
element with an invalid index.
4. IndexOutOfBoundsException: A general exception for index-related errors.
5. IllegalArgumentException: Thrown when an illegal argument is passed to a method.
6. NumberFormatException: Thrown when an invalid conversion to a numeric type is
attempted (e.g., parsing a non-numeric string as an integer).
7. ClassCastException: Thrown when an inappropriate type cast is made.
8. FileNotFoundException: Thrown when an attempt to open a file fails because the
file does not exist.
9. IOException: A general exception for input/output errors.
10. InterruptedException: Thrown when a thread is interrupted while it's waiting,
sleeping, or otherwise occupied.
11. NoSuchElementException: Thrown by collection classes like java.util.Iterator when
there are no more elements to retrieve.
12. SecurityException: Thrown when a security violation occurs.
13. UnsupportedOperationException: Thrown when an operation is not supported,
often in the context of immutable objects.
14. IllegalStateException: Thrown when an object is in an inappropriate state for the
requested operation.
15. OutOfMemoryError: Not an exception but an error, thrown when the JVM runs out
of memory.
16. StackOverflowError: Not an exception but an error, thrown when the call stack
exceeds its limit.

These are just some of the commonly used predefined exceptions in Java. Java provides
many more exception classes, each designed to handle specific types of errors, making it
easier to write robust and reliable code.

You might also like