throws
Declares that a method may throw one or more checked exceptions, requiring callers to handle or re-declare them.
Syntax
java
returnType methodName(params) throws ExceptionType { }Example
java
public void readFile(String path) throws IOException {
FileReader fr = new FileReader(path);
// ...
}
// Caller must handle it:
try { readFile("data.txt"); }
catch (IOException e) { e.printStackTrace(); }