Ответ:
In Java, exceptions are categorized into two main types: checked exceptions and unchecked exceptions. Here are some of the mainstream exceptions in Java:
Checked Exceptions
These exceptions are checked at compile-time. The programmer is required to handle these exceptions explicitly.
- IOException - Signals that an I/O exception of some sort has occurred.
- SQLException - Provides information on a database access error or other errors.
- ClassNotFoundException - Thrown when an application tries to load a class through its string name but cannot find the definition of the class.
- FileNotFoundException - Signals that an attempt to open the file denoted by a specified pathname has failed.
- ParseException - Indicates that an error has occurred while parsing a string.
- InterruptedException - Thrown when a thread is interrupted while it is waiting, sleeping, or otherwise occupied.
- NoSuchMethodException - Thrown when a particular method cannot be found.
- InvocationTargetException - Wraps an exception thrown by an invoked method or constructor.
- CloneNotSupportedException - Thrown when the
clone()
method in class Object
is called to clone an object, but the object's class does not implement the Cloneable
interface.
Unchecked Exceptions
These exceptions are not checked at compile-time. They are subclasses of RuntimeException
.
- NullPointerException - Thrown when the application attempts to use
null
in a case where an object is required.
- ArrayIndexOutOfBoundsException - Thrown to indicate that an array has been accessed with an illegal index.
- ArithmeticException - Thrown when an exceptional arithmetic condition has occurred, such as division by zero.
- ClassCastException - Thrown when an object is cast to a class of which it is not an instance.
- IllegalArgumentException - Thrown to indicate that a method has been passed an illegal or inappropriate argument.
- IllegalStateException - Signals that a method has been invoked at an illegal or inappropriate time.
- IndexOutOfBoundsException - Thrown to indicate that an index of some sort (e.g., an array or string) is out of range.
- UnsupportedOperationException - Thrown to indicate that the requested operation is not supported.
- ConcurrentModificationException - Thrown when a collection is modified while iterating over it in a way that is not allowed.
These exceptions are commonly encountered in Java programming and are essential for error handling and debugging.