Exception handling is an important feature in Java that helps manage runtime errors effectively. Two commonly used keywords in exception handling are throw and throws.
Although their names look similar, they serve completely different purposes.
✅ What is throw Keyword?
The throw keyword is used to explicitly create and throw an exception inside a method or block of code.
Syntax:
throw new ExceptionType("Error Message");
Example:
```java id="4f2g6p"
public class ThrowExample {
public static void main(String[] args) {
int age = 15;
if (age < 18) {
throw new ArithmeticException("Not eligible to vote");
}
}
}
### Key Points:
* Used to throw an exception manually
* Used inside method body
* Throws only one exception at a time
---
## ✅ What is `throws` Keyword?
The **throws** keyword is used in the **method declaration** to specify that a method may generate exceptions.
### Syntax:
```java
returnType methodName() throws ExceptionType {
}
Example:
```java id="1y6hka"
import java.io.IOException;
class ThrowsExample {
static void readFile() throws IOException {
throw new IOException("File error");
}
}
### Key Points:
* Declares possible exceptions
* Used in method signature
* Can declare multiple exceptions
---
## 📊 Difference Between throw and throws
| Feature | throw | throws |
| -------------------- | --------------------------- | -------------------- |
| Purpose | Explicitly throws exception | Declares exceptions |
| Usage Location | Inside method | Method declaration |
| Number of Exceptions | One at a time | Multiple allowed |
| Keyword Type | Action keyword | Declaration keyword |
| Used With | Exception object | Exception class name |
---
## ✅ Simple Understanding
* **throw → actually creates the exception**
* **throws → informs the compiler that exception may occur**
---
## 🎯 Interview Tip
A common interview question:
👉 *Can we use throw without throws?*
Yes. Runtime exceptions can be thrown using `throw` without declaring them using `throws`.
---
## 🚀 Top Java Real Time Projects Online Training in 2026
Want to master Java Exception Handling, Collections, Multithreading, and Spring Boot through real-time projects?
Join industry-oriented training designed for students and job seekers.
**[Top Java Real Time Projects Online Training in 2026](https://ashokitech.com/java-real-time-projects-online-training/)**
✔ Core Java & Advanced Java concepts
✔ Real-time project implementation
✔ Spring Boot & REST API development
✔ Interview preparation support
✔ Practical sessions by real-time experts at ashok it
Build strong Java development skills and become industry-ready with hands-on project experience.
Top comments (0)