The advantages of using the standard exceptions provided by the Java library are as follows.
Easy to learn and understand as it follows customs
Easy to read as it does not use unfamiliar exceptions
Below, the exceptions in the Java library are shown.
IllegalArgumentException: Thrown when a non-null, inappropriate iron argument is received
IllegalStateException: Thrown when the state of the receiving object is incorrect. Thrown, for example, if an object has been used before it has been properly initialized.
NullPointerException: Throw when the parameter becomes null where null is prohibited
IndexOutOfBoundsException: Throws when accessing outside the range of parameters such as lists
ConcurrentModificationException: An object created on the assumption that it will be used in a single thread is thrown when parallel execution is detected.
UnsupportedOperationException: Throw when using a method that the object does not support
When reusing an exception, you must look at the exception's documentation to make sure it is in line with your intentions.
Recommended Posts