Home / Questions / What is the throws keyword, and how does it differ from the throw keyword?
Explanatory Question

What is the throws keyword, and how does it differ from the throw keyword?

👁 29 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

  • throw → used to manually generate an exception.

  • throws → used to declare that a method might throw an exception.

Example:


void myMethod() throws IOException {
   throw new IOException("File not found");
}