有人可以帮我解决这些抛出的异常问题吗? [英] can someone help me with these thrown exception problem?

查看:92
本文介绍了有人可以帮我解决这些抛出的异常问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MFC计划抛出异常。当我试图调试编译器指向afxtempl.h中的一行时。



也许,我应该提供更多细节。该程序是一个MDI MFC程序,它创建了三个分割器。在下面显示的CChildFrame :: OnCreateClient代码中,程序成功创建了第一个声明的窗格,但无法创建第二个窗格。任何人都可以给我一些指导。(上一段是在稍后的版本中添加的)< br $> b $ b

My MFC program threw an exception. When I tried to debug the compiler pointed to a line in afxtempl.h.

Perhaps, I should give more details. The program is an MDI MFC program that creates three splitters. In the "CChildFrame::OnCreateClient" code shown below, the program successfully creates the first stated pane, but unable to create the second pane.Can any one give me some guidance.(The previous paragraph was added at a much later revision)

template<class TYPE, class ARG_TYPE>
AFX_INLINE TYPE& CArray<TYPE, ARG_TYPE>::ElementAt(INT_PTR nIndex)
{ 
	ASSERT(nIndex >= 0 && nIndex < m_nSize);//This is the line it pointed to
	if(nIndex >= 0 && nIndex < m_nSize)
		return m_pData[nIndex]; 
	AfxThrowInvalidArgException();		
}





以上功能是以下功能:





The above function is a memeber function of:

template<class TYPE, class ARG_TYPE = const TYPE&>
class CArray 





老实说,我不知道如何去定位这些bug。该程序继续成功运行光标位于我怀疑该bug可能位于的所有位置。这意味着我觉得这个bug的所有位置都可以测试bug。

任何人都可以提供指导吗?





进一步调试产生了以下发现:





Honestly, I don't know how to go about location these bug. The program keep running succesfully to cursor located past all the places I suspected the bug might be located. Meaning that all the location I feel the bug could be tested negetive for the bug.
Can anyone give a guidance ?


Further debugging produced the following discovery:

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
	if( !CMDIChildWndEx::OnCreateClient(lpcs,pContext))
	{
		return FALSE;
	}
	
	if(!m_wndSplitter->CreateStatic(this,1,3,WS_CHILD))
	{
		return FALSE;
	}


	//Calculate the size of splitter
	SIZE size;
	CRect rect;
	GetClientRect(&rect);
	size.cx = (rect.right - m_wndSplitter->GetSplitterWidth())/3;
	size.cy = rect.bottom;

	//Set the views
	m_wndSplitter->CreateView(0,1,RUNTIME_CLASS(CClassManagerView),size,pContext);
	//Code successfully ran to this point
	m_wndSplitter->CreateView(0,2,RUNTIME_CLASS(CCalcView),size,pContext);
        //code failed to run to this point
	m_wndSplitter->CreateView(0,0,RUNTIME_CLASS(CDisplayView),size,pContext);

	SetActiveView((CView *)m_wndSplitter->GetPane(1,2));

	//Show the splitter
	m_wndSplitter->ShowWindow(SW_SHOWNORMAL);
	m_wndSplitter->UpdateWindow();

	return TRUE;
}





我试图进入无法执行的代码行,但visual studio只指向GetThisClass 只是简单地把我送到了班级的.cpp代码。

任何人都可以帮我解决这些进一步的问题。



由方式,进一步调试显示代码:





I tried to step into the line of code that failed to execute, but visual studio only pointed to "GetThisClass" and just simply sent me to the .cpp code of the class.
Can anyone help me with these further revealations.

By the way, futher debugging showed that the code:

int CCalcView::OnCreate(LPCREATESTRUCT lpCreateStruct)



成功运行。


ran successfully.

推荐答案

从调试器开始:忽略它的行报告问题,并通过调用堆栈查找导致问题的代码行。有可能它接近它的代码,但它几乎肯定会是某种数据问题 - 所以看看索引值,并在对象上进行索引并尝试找出断言失败的原因。无论是指数是负数还是大于集合,所以你需要做的就是找出原因!



我们无法帮助你在这里:我们无法运行您的代码(我们还没有),我们无法访问您的数据(我们无法看到您的屏幕,访问您的硬盘或阅读您的想法)。
Start with the debugger: ignore the line it's reporting the problem on, and look through the call stack to find the line of your code that "caused" the problem. Chances are it's code near that, but it will almost certainly be a data problem of some sort - so look at the index value, and at the object it's indexing and try to work out why the assert fails. It'll be either that the index is negative or bigger than the collection, so all you need to do then is work out why!

We can't help you here: we can't run your code (we haven't got it) and we don't have access to your data (we can't see your screen, access your HDD, or read your mind).


这篇关于有人可以帮我解决这些抛出的异常问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆