Hey guys, i got this program im making. It encrypts and decrypts files. The problem is that whenever an error occurs while encrypting or decrypting ( having put a read-only file, a running program, input wrong keys, enter wrong encryption type...) the program tells me that an error occured. Thats nice and everything but i have to close the program, restart it and then try again. I can't just correct the mistake. If i do correct the mistake and try again, i get an error message again.

Basically i want to be able to correct mistakes without having to restart program. Does anyone know what to do?

It'll be great if someone can. Thanks in advance!

To summarize, you want to know how to write a robust program. Unfortunately, that's an art that takes experience and practice. There aren't really any tricks to it. Just know what errors could possibly happen and write code to handle them gracefully (such as with try..catch blocks).

obviously everyone would want to create a perfect program, but you know it doesnt always work out to plan. ok concerning the try...catch blocks, i already got that. Whenever an error occurs in the process, it tells me! thats fine and great! BUT, if i try to do the process again, it gives an automatic error, even though the information it wants is correct! I have to close the program to be able to make it work.
i was wondering if there was some sort of code that involves a "dispose" code for an open file. I would like ti put that in the catch block

Just because it tells you there's an error doesn't mean your using try/catch block correctly. It will tell you there is an error even if you have any try/catch blocks. You need to try to handle the error in the try catch block.

From what you described, you need to reset the variables you're using inside the try/catch blocks or reset them when the encrypting is done (i.e. in a finally block). I'm like 99.99% sure that's what your problem is.

i dont think you understand... i programmed it to tell me there is an error. But i don't know, like you say, handle the error.

would you know some sort of reset code?

This article has been dead for over six months. Start a new discussion instead.