throws keyword.
For example, consider the following Java program that opens the file none.txt”main() uses FileReader() and FileReader() throws a checked exception FileNotFoundException.
It also uses readLine() and close() methods, and these methods also throw checked exception IOException.
throws, or we need to use try-catch block.
We have used throws in the following program.
Since FileNotFoundException is a subclass of IOException, we can just specify IOException in the throws list and make the above program compiler-error-free.
|
Whether it’s the best of times or the worst of times, it’s the only time we’ve got. |