Can userdefined exception have two methods in it?
Yes a user defined exception can have any number of methods in it.
A user defined exception is nothing but a Java class created for a specific purpose. Just like ordinary Java classes, you can have any number of methods in it...
It is called an exception. There are two ways of handling exceptions inside java methods. The method can have a try catch block and handle the error/exception inside the method. Or The method can throw the exception under the assumption that the calling method would have the code to handle the exception that is thrown by this method
An IllegalArgument exception is usually generated when the arguments passed to a method do not match the data type of the arguments the method expects. Most of these problems are caught by the compiler but in cases where Java Reflection is used to generate and call methods dynamically, we can often encounter this exception.