I have the following code:
try {
fi.MoveTo(getHistoryFileName());
} finally {
Debug.Write("Move complete");
}
I thought that using this would make sure that I’d never have exceptions thrown, but I am getting IOExceptions sometimes. What is the reason?
finally does not catch thrown exceptions; it guarantees that code in it will execute regardless of whether an exception is thrown in the try block.
You are going to want to catch the exceptions and then handle them appropriately. A Catch block would be between the Try and Finally blocks and start with something like this:
You could replace Exception with a more specific exception to just handle that exception.