Home / Questions / What is the difference between throw and throws clause?
Explanatory Question

What is the difference between throw and throws clause?

👁 62 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Solution:

Keyword Purpose Used In Example
throw Used to explicitly throw an exception from a method or block of code. Inside a method or block. throw new IOException("File not found");
throws Used to declare that a method may throw certain exceptions. In the method declaration. void readFile() throws IOException

Explanation:

  • throw is used when you want to manually raise an exception.

  • throws is used when you want to inform the caller that this method might throw an exception that it must handle.