I have to use a library without source which also does not handle exceptions. Whenever an exception occurs inside it, effectively many of the destructors included never return. In the app, I have included a flag in the exception handlers to detect the erroneous state of the DLL.
- I need something so that my program doesn't get stuck in the DLL at destruction while trying to destroy the objects contained as the destructors never return nor throw exceptions.
OR
- Should I leave out the destruction when such scenario arises and hope for the OS to cleanup the zombies?
Both options are possible.
1- try do destroy the objects
If you want to speculatively call a routine inside the DLL you'll have to put it inside a separate thread. put the mean thread to sleep and if the call does not return within the stated time assume that it hung.
2- just end the program
Windows will clear up all memory and GDI objects that a program used when it is terminated.
If you have open files where data has not been flushed out, lose data there, so depending on the nature of the application this may be a bad idea.
Here's how to do the cleanup in a separate thread:
Warning
Note that you cannot call
synchronize
or your thread will not run in parallel anymore. Also note that you cannot more thread unsafe calls in your code. All of GDI and all user interface stuff is out, those need to be handled in the main thread (i.e. the program itself).