2. From what was advised, trying to capture an error and then forced file close before exit seemed pretty simple. But it assumed, that I know what exception to capture. Because capturing the exception "File cannot be cleared as it is held" gives me nothing, as it is already late. To find this exception I've placed several "printf" into the program to trace it somehow. But :-((( it never crashed since that time. Before that it crashed almost every day...