Hello everybody

I recently published a thread concerning two questions, but got answered for only one of them, so here Im asking the second one again, hope you could help me..

How can I detect an unexpected termination of a program?
My program encrypts files, how can I possibly roll back the changes that were made on the file if he was not fully encrypted / decrypted (and therefore will never go back to it's original state)?

thanks