✏️ Explanatory Question

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

👁 33 Views
📘 Detailed Answer
🔴 Hard
💡

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");
}