Throw keyword in Java Exceptions | Core Java Tutorials

This “Throw keyword in Java Exceptions” is explaining clearly about how to use ‘throw’ keyword in java exception handling to throw user exception objects.

core-java-online-training-3

throw:

  • Exception is a class.
  • It is either pre-defined or user-defined.
  • 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”.

 

Creating & Throwing pre-defined Unchecked exception object(ArithmeticException) :

 

Creating & Throwing pre-defined Checked exception object(IOException):

 

Defining, Creating, throwing, collecting and Handling user exception object :

core-java-online-training-3

Share this