Re: ? Handling assertions
From: Alec S. (a_at_a.com)
Date: 08/17/04
- Next message: Jeff F: "Re: CTreeView COleDataSource::DoDragDrop WM_MOUSEMOVE"
- Previous message: Vincent Finn: "Re: template function prototype"
- In reply to: Jonathan Wood: "Re: ? Handling assertions"
- Next in thread: Trevor: "Re: ? Handling assertions"
- Reply: Trevor: "Re: ? Handling assertions"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 17 Aug 2004 13:17:43 -0400
I know it is settings up something invalid. That's why I want to handle it.
I need to allow the user to manually input the handle for a window or the
CWnd pointer. Here's a stripped down example of the code:
...
HWND handle=m_HANDLE;
CWnd* wnd=FromHandle(handle);
try
{
CString t;
wnd->GetWindowText(t);
}
catch (...) {
wnd=NULL;
AfxMessageBox("That handle is invalid.");
}
...
This does not work because it gives me an assertion. However, using similar
code works just fine:
...
CWnd* wnd=(CWnd*)m_POINTER;
try
{
CString t;
wnd->GetWindowText(t);
}
catch (...) {
wnd=NULL;
AfxMessageBox("That handle is invalid.");
}
...
The reason that the second one works is because an invalid window
pointer causes an exception. The first one is a little different. If I
input an invalid handle, I still manage to get a valid CWnd*, but using
GetWindowText on it causes an assertion. Therefore there is no exception
and my validity check does not work.
What can I do to get around this? Is there a better way to test if a
CWnd*/HWND is valid?
-- Alec S. alec <@> synetech <.> cjb <.> net "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:eqa1gYBhEHA.592@TK2MSFTNGP11.phx.gbl... > You are not supposed to handle assertions other than by reworking your code. > In effect, assertions identify bad programming. You provided very little > info about the line that causes the assertion. You should be able to use > Retry to step through the code. Either way, your code is setting up > something invalid somehow and you need to figure out what is happening so > you can rework it. > > -- > Jonathan Wood > SoftCircuits > http://www.softcircuits.com > Available for consulting: http://www.softcircuits.com/jwood/resume.htm >
- Next message: Jeff F: "Re: CTreeView COleDataSource::DoDragDrop WM_MOUSEMOVE"
- Previous message: Vincent Finn: "Re: template function prototype"
- In reply to: Jonathan Wood: "Re: ? Handling assertions"
- Next in thread: Trevor: "Re: ? Handling assertions"
- Reply: Trevor: "Re: ? Handling assertions"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|