This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Java tutorial mentions that one of the uses of Finally section is to close any open IO streams. That's what I did in the following code. However, I get "IoTest2.java [30:1] unreported exception java.io.IOException; must be caught or declared to be thrown" error when I compile the code. How should I hadle exceptions thrown in Finally section?
import java.io.*; public class IoTest2 {
/** Creates a new instance of IoTest2 */ public IoTest2() { }
Originally posted by satish: How should I hadle exceptions thrown in Finally section?
The same way you handle them anywhere else: catch them or declare that they will be thrown from the method. Since you print the message of any IOException that occurs while using the file, you may as well do the same when closing it.