Home / Questions / What type of exceptions must be explicitly declared in a throws clause of a method?
Explanatory Question

What type of exceptions must be explicitly declared in a throws clause of a method?

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

All exceptions except those of type RuntimeException and Error must be explicitly declared in a method’s throws clause.
In other words, checked exceptions must be declared, while unchecked exceptions do not require declaration.

Example:


public void readFile() throws IOException {
    // Code that may throw IOException
}