Sometimes, the built-in exceptions in Java are not able to describe a certain situation. In such cases, user can also create exceptions which are called ҵser-defined ExceptionsҮ Following steps are followed for the creation of user-defined Exception.
The following program illustrates how to create own exception class MyException. Details of account numbers, customer names, and balance amounts are taken in the form of three arrays. In main() method, the details are displayed using a for-loop. At this time, check is done if in any account the balance amount is less than the minimum balance amount to be ept in the account. If it is so, then MyException is raised and a message is displayed Balance amount is less.
Runtime Error:
Output: