Question

I am new to VC++ and I have good experience in working with C# on .net platform. Presently I am in a project which is a combination of VC++ and C# on .net platform.

I used to add centralized exception handling for all windows form applications developed using C#. What I mean by centralized exception here means something like this http://www.codeproject.com/KB/cs/GlobalExceptionHandling.aspx

Now the problem is in my new project there is a legacy application which is in VC++. Changes have been made in the project so that it compiles in Visual Studio 2008 but the code is still unmanaged VC++. I see a lot of { try catch } in the present code and exceptions being handled locally without the application coming to know of the consequences.

I wanted to know if I can add centralized exception handling to this legacy VC++ forms application like I do for C# forms applications(using CurrentDomain_UnhandledException, etc). If yes where do I add this exception handling and how do I add it. A sample illustration would be of great help.

Was it helpful?

Solution

You can utilize the set_unexpected (<exception>).

Alternatively, you can use SetUnhandledExceptionFilter function; which enables an application to supersede the top-level exception handler of each thread of a process.

After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top