We have a system that lets a user upload a file, we loop through that file and then make another file. The user that uploads the file is a logged in user.
Problem is that the files contain sensitive data so we have to delete them. As you can imagine there are a few places that write more info to the file and read the file. Sometimes an error happens on this page (normally something to do with CFFILE).
So my question is, is it fine to place all the code (most of it anyway) in a giant CFTRY? Then catch any exception that happens, then run another CFTRY inside the CFCATCH to delete the 2 files?(Read the update) I’m not too worried about performance as this process is not done a million times a day, maybe 3 times a month.
Is this acceptable practice for making sure files are deleted?
UPDATE I wont be deleting the files in the CFCATCH. I’ll first check if the exist. Then delete them.
I had to write a new section of code that almost did the same thing as what I asked. Instead of writing individual lines to the file and then wrapping a big CFTRY around that. I instead wrote each line to a variable and ended each line with a new line character, in my case (Windows) the new line characters where
Chr(13) & Chr(10). But you should rather use the following line of codeWhich will make the variable
NLequal to the current system new line character.Then you can have a small CFTRY where you can write the entire variable to a file.