Creating An Exception in Java

You can make your own exemptions in Java. Remember the accompanying focuses when composing your classes for exceptions:

  • All exemptions must be an offspring of Throwable.
  • If you need to compose a checked exemption that is naturally authorized by the Handle or Declare Rule, you have to create an extension of the Exception class.
  • If you need to compose a runtime exemption, you will have to create an extension of the Runtimeexception class.

You can create your own exceptions using the following structure:

class MyNewException extends Exception{ }


 

For any query or issue, feel free to discuss on http://discuss.eduguru.in