Introduction
An exception is an event that happens during the execution of a program that hampers the overall execution of the code. Sometimes, the system handles the exception by default, but in some cases, we need to explicitly handle exceptions based on our code or situations.
Java exception handling is managed via five keywords: try, catch, throw, throws, and finally. The brief description of throw and throws in Java Exception Handling keywords are as follows.

Though they look similar but these two keywords are very different:
- Throws is used to indicate that an exception can be thrown by a function during execution.
-
Throw can be used to throw an exception explicitly within a function or within a block of code.
Let's deep dive into the topics one by one and discuss them in detail.
Must Read, Multithreading in java, Duck Number in Java
What is Throw Keyword in Java?
Throw in Java is used to explicitly throw an exception from a method or constructor. We can throw either checked or unchecked exceptions in java by throw keyword. The "throw" key-word is mainly used to throw a custom exception. The only object of the throwable class or its subclasses can be thrown. When a throw statement is encountered, program execution is halted, and the nearest catch statement is searched for a matching kind of exception.
Syntax of Throw in Java:
throw new ArithmeticException("Arithmetic Exception");
void myMethod() {
try {
//throwing arithmetic exception using throw
throw new ArithmeticException("Something went wrong!!");
} catch (Exception exp) {
System.out.println("Error: " + exp.getMessage());
}
}
Example of Throw in Java:
Output:
Explanation:
In this example, we have created the validateMarks() method that takes an integer value as a parameter. If the marks is less than 80, we are throwing the ArithmeticException otherwise, print a message that you are Oracle certified.
Also see, Swap Function in Java