Clean up resources

I have C# Windows Forms application which works with C++/CLI Library. Library class works with camera and has clean-up function ShutDown. Wnen C# client exits, it calls ShutDown function and all works OK:

Camera camera;          // form class member

    camera = new Camera();


But when program has unhandled exception, camera.ShutDown function is not called. Result of this is that process remains active and must be killed from Task Manager. How can I call this function in any case?
LVL 48
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMAuthor Commented:
Camera class has destructor which calls ShutDown, but this destructor is not called in the case of exception.
I think you have to handle yourexceptions with try catch finally block.  In the case of unhandled exception i don't think anything gets called
AlexFMAuthor Commented:
I don't want to handle all exceptions, I handle only exceptions which I expect to happen. Bugs in the program must remain unhandled. My problem is that class instance is not destroyed after unhandled exception.
Have a read at this it may help

Does the app actually crash when you have an unhandled exception? or does it continue

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexFMAuthor Commented:
It looks exactly like my case. The bad news are that there is nothing to do with this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.