When reading or writing to files, what should you have in a try-catch?
And should you have a finally?

Should I have everything in the try?
Like.. maybe create a File variable to check if a file with that name exists etc and throw errors if they do.
And then open the file and write to it?
And have the printWriterVariable.close() in the finally?


or something like this..

PrintWriter pw = null;
		
		try
		{
		 pw = new PrintWriter( new BufferedWriter( new FileWriter(filNamn, true) ) );
		}
		catch(IOException error)
		{
			System.out.println("\Something went wrong, e.message:"+error.getMessage());
			
			return;
		}

Anyone?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.