User Defined Exceptions in Java | Core Java Tutorials

This “User Defined Exceptions in Java” post is providing clear information about how to create user defined exceptions in java application with clear example codes.

core-java-online-training-3

throw:

  • Exception is a class.
  • Exception is either pre-defined or user-defined.
  • Java API is providing many pre-defined exception classes.
  • We can create User exceptions also.
  • It is allowed to create user exceptions by extending functionality from pre-defined exception.
  • User exception can be either Checked or Unchecked.
  • Most of the User exceptions are “Checked”.

 

  • “throw” keyword is used to throw an exception object.
  • In case of pre-defined exceptions, if exception has risen, JVM creates and throws.
  • But in case of User exception, we need to create and throw.

 

  • JVM implicitly does all the above steps when exception raises.
  • As programmer we can perform all the above steps explicitly.
  • Creating & Throwing pre-defined Unchecked exception object : For example, take ArithmeticException class.

core-java-online-training-3

Share this