This class throws our defined exception, i. Here in the code above, we have made our own exception class, myException2 by extending Exception class.
This may confuse the person who is analyzing all the exceptions. Do not catch top level exceptions in general until a lower level exception cannot be found suitable for the try block logic. Next, we will use throws keyword, to throw the exception out of the method from where our defined exception was generated.
Creating our own exception and throwing it with throw Keyword In the upcoming code, we are creating our own exception class by extending the Exception class, which is the mother of all the exception classes. Low Account Balance.
API can identify checked exceptions and intimate the same so that programmer can catch them as needed. Let's see how. Please share this article .