Catching exceptions in MFC
Posted on 1999-11-30
I'm using VC 6 with MFC
We have implemented a design by contract technique in our code and
it's working well.
The technique is simple, we simply have to put a condition that will verify if
the "contract" is respected. If not, we simply throw an exception.
At some strategic places, we have try-catchs in wich we can display
to user the cause of the exception.
Those exception are like the ASSERTs we can see in MFC Code.
I think that MFC removes those ASSERTs in release mode.
The problem I'm facing is that those strategeic "try-catch" are easy
to place in our generic classes but I don't know where to place them when
we are using the MFC framework.
Here is an example:
I have a dialog in which I placed intentionally a pre-condition that is always false
(for the purpose of this example only)
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
Think of the PRE_COND macro as an ASSERT that throws a user exception derived
from CException if the contract that it contains is not respected (is false).
My problem is that my exception is caugth in MFC
LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg,
WPARAM wParam = 0, LPARAM lParam = 0)
// Catch exceptions thrown outside the scope of a callback
// in debug builds and warn the user.
(...) // It is caugth right here
// and it simply display "internal error" on screen
Is there something I can do to intercept that process before MFC does
without having to place a try catch in every method of every interface classes ?
Thanks for the help.