M
Mike N
Coming from a C++ background, are destructors called for all local
objects after a C# exception?
C++:
myproc() {
CSingleLock protect(&m_myCritsec, FALSE);
if (!protect.Lock())
{
// Handle error
}
// more stuff that can throw an exception
}
.... You know that the critical section for 'protect' is released
properly because its destructor will be called regardless of an
exception.
If I understand C#, you could not develop a similarly functioning
CSingleLock class because the destructor is called only at some later
random point by the garbage collection. So to properly release
semaphores, etc, you must use a try...finally construct everywhere,
manually track everything that might have been locked/used and make
sure it is released?
objects after a C# exception?
C++:
myproc() {
CSingleLock protect(&m_myCritsec, FALSE);
if (!protect.Lock())
{
// Handle error
}
// more stuff that can throw an exception
}
.... You know that the critical section for 'protect' is released
properly because its destructor will be called regardless of an
exception.
If I understand C#, you could not develop a similarly functioning
CSingleLock class because the destructor is called only at some later
random point by the garbage collection. So to properly release
semaphores, etc, you must use a try...finally construct everywhere,
manually track everything that might have been locked/used and make
sure it is released?