I presume you're using files? You need to consider the possibilities as to why you were not able to write to the file:
1) Maybe you don't have write permission
2) Maybe the file is marked as 'read only - can be determined by using the canWrite() method of File.
3) Maybe your disk is full
4) Etc...
I have one tip for handling this type of error - display an appropriate message to the user, perhaps this:
'The program was unable to write to the specified file. This may be because you do not have adequate write permission for the file. Or the disk may be full.'