Possible Duplicate:
How do I prevent and/or handle a StackOverflowException? (C#)
C# catch a stack overflow exception
I have a fairly complex application written in C# (using .NET 2.0). The program processes a large number of files in a heavily recursive way and at some clients it runs into a stack overflow exception. The program is very complex and we haven't been able to even reproduce the problem - not even at our clients where it happened.
The obvious solution is to fix the code that causes the stack overflow but that doesn't seem very likely - our code base is well over 2 million lines of code that creates a large recursive data structure in memory. It's not likely that we'll just stumble upon the problem part. (Not in the short term, anyway.)
However, our program also backs up files and makes changes to the ones being processed and in case of exceptions, it restores everything into the original state. When a stack overflow exception happens, the process just terminates and this restore functionality doesn't have a chance to run because stack overflow cannot be caught.
So my question is: is there a way to catch a stack overflow exception in .NET 2.0. I can't host the CLR and the exception is a true stack overflow, not thrown by our code. Being able to do this would at least give me the ability to revert changes made before the program terminates.
Edit: Please note, I'm well aware of what a stack overflow exception is and how serious it is. I'm not looking for advice in finding one - this situation happens rarely. What I'm trying to do is restore client data in an environment with limited disk space when it happens. If my program dies after the restore operation, I'm ok with that.