try中的break问题
试看如下代码,从思路上讲,程序运行到20行tray中的break,按照道理应该跳出while,运行至40行。可实际调试的情况是程序跳转至了44行,执行了返回操作,然后又跳转至40行继续执行。虽然能正常执行,但是让人很难理解。最好的修改为将break移至try之外。
1void CPCBVisionCutView::OnBnClickedButtonLeftProductionCountClear2()
2{
3 // TODO: Add your control notification handler code here
4 int i=0;
5 void *pImageBuf = NULL;
6 while (1)
7 {
8 pImageBuf = g_pCamera->fnGetImagePtr(0);
9 if (pImageBuf)
10 {
11 int nWidth = 0;
12 g_pCamera->fnGetImageWidth(0, nWidth);
13 int nHeight = 0;
14 g_pCamera->fnGetImageHeight(0, nHeight);
15 //pMainFrame->m_ImageSrc->SetWidth(nWidth);
16 //pMainFrame->m_ImageSrc->SetHeight(nHeight);
17 try
18 {
19 pMainFrame->m_ImageSrc->SetImagePtr( nWidth,nHeight, pImageBuf);
20 break;
21 }
22 catch (EException& e)
23 {
24 pView->AddAError(_T("snap image error"));
25 }
26
27 }
28 else
29 {
30 if (i>=5)
31 {
32 pView->AddAError(_T("camera offline!"));
33 return ;
34 }
35 i++;
36 MSDelay(200);
37 }
38 }
39
40 if (pMainFrame->m_ImageSrc3->GetWidth() < 10)
41 {
42 pMainFrame->m_ImageSrc3->SetSize(pMainFrame->m_ImageSrc->GetWidth(), pMainFrame->m_ImageSrc->GetHeight());
43 }
44}