I am performing a series of steps, when I run the console application. Let’s say the number of steps are 8, and it fails somewhere at the 4th step.
I wanted to be able to revert the first steps that I did before it failed. How can this be done, if it fails at any of steps?
If you implement the steps using the command pattern where each step knows how to do itself as well as undo itself. Then you would be able to just loop through the steps that have been done and undo them.
You may also be interested in this question Implementing the command pattern.