Throw Keyword in JAVA (User Defined Exception)


This tutorial is all about Throw Keyword in JAVA (User Defined Exception)
In this article we will discuss about “throw” keyword in Java. Usage of throw keyword is anti to exception handling that is we are raising exception and not handling it.

Let us take an example to understand this better.


import java.util.Scanner;

public class Manager{

public static void main(String args[]) {

Scanner sc=new Scanner(;

System.out.println(“Enter age”);

int age=sc.nextInt();

if (age <= 0) {

throw new Arithmetic Exception () ;


System.out.println (“continue” );




As JRE and compiler doesn’t distinguish zero, positive and negative integers. So in any case if someone enter age as zero or negative value , it is violating business logic. In order to terminate the program while such conditions occurs , we are guiding JRE not to execute the program as the condition is not suitable from business perspective.


Readers might read also:




Facebook Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.