Throws and Throw
You can choose not to deal with some caught exceptions in your code at a low level, as described in the previous section. It could be interesting to filter out an exception's parent class and focus on detecting a subclass that might be of more importance to us. The throws
keyword is used in the definition of the method you are creating and where the exception may occur. In the following case, which is a modification of Example 09, we should call throws in the definition of main()
:
import java.io.*; import java.nio.file.*; import java.util.*; public class Example10 { public static void main(String[] args) throws IOException { // declare a list that will contain all of the lines // inside of the readme.txt file List<String> lines = Collections.emptyList(); &...