CATCH_ALL and OnCtlColor
-
Hello I was trying to debug this code (see below), because after a few minutes it crashes. So I used a
try{ }catch(...)
to catch the exception but I dont know what type of exception it was. Is there a way to tell? I tried usingTRY{} CATCH_ALL()
but it dod not catch anything??try{ DeleteObject(hbr); //must be deleted or eventually mem overflow hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC ) { CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); this->ScreenToClient(&Rect); COLORREF Clr = GetDC()->GetPixel(Rect.left-1, Rect.top-1); hbr = CreateSolidBrush(Clr); ASSERT(pDC); if(!m_staticTextBgd) pDC->SetBkColor(Clr); pDC->SetTextColor(RGB(m_fntR,m_fntG,m_fntB)); pDC->SetBkMode(m_staticTextBgd?OPAQUE:TRANSPARENT); } } } catch(...) { printf("Error"); }
I tried catching CResourceException and CMemoryException and many others but it did not catch anything? How do I know what exception is being thrown? --- -
Hello I was trying to debug this code (see below), because after a few minutes it crashes. So I used a
try{ }catch(...)
to catch the exception but I dont know what type of exception it was. Is there a way to tell? I tried usingTRY{} CATCH_ALL()
but it dod not catch anything??try{ DeleteObject(hbr); //must be deleted or eventually mem overflow hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC ) { CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); this->ScreenToClient(&Rect); COLORREF Clr = GetDC()->GetPixel(Rect.left-1, Rect.top-1); hbr = CreateSolidBrush(Clr); ASSERT(pDC); if(!m_staticTextBgd) pDC->SetBkColor(Clr); pDC->SetTextColor(RGB(m_fntR,m_fntG,m_fntB)); pDC->SetBkMode(m_staticTextBgd?OPAQUE:TRANSPARENT); } } } catch(...) { printf("Error"); }
I tried catching CResourceException and CMemoryException and many others but it did not catch anything? How do I know what exception is being thrown? ---Try catching a CException, that might work. If it does get the error message and it might help you figure out what type of exception is being thrown. - Aaron
-
Try catching a CException, that might work. If it does get the error message and it might help you figure out what type of exception is being thrown. - Aaron
-
Hello I was trying to debug this code (see below), because after a few minutes it crashes. So I used a
try{ }catch(...)
to catch the exception but I dont know what type of exception it was. Is there a way to tell? I tried usingTRY{} CATCH_ALL()
but it dod not catch anything??try{ DeleteObject(hbr); //must be deleted or eventually mem overflow hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC ) { CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); this->ScreenToClient(&Rect); COLORREF Clr = GetDC()->GetPixel(Rect.left-1, Rect.top-1); hbr = CreateSolidBrush(Clr); ASSERT(pDC); if(!m_staticTextBgd) pDC->SetBkColor(Clr); pDC->SetTextColor(RGB(m_fntR,m_fntG,m_fntB)); pDC->SetBkMode(m_staticTextBgd?OPAQUE:TRANSPARENT); } } } catch(...) { printf("Error"); }
I tried catching CResourceException and CMemoryException and many others but it did not catch anything? How do I know what exception is being thrown? ---Appart from not knowing how to get infomation from an unknown exception, I have fixed my code problem.
COLORREF Clr = GetDC()->GetPixel(Rect.left-1, Rect.top-1);
This line does not like being called so often.(why??) So I just set Clr to the background color as it actually does not change after initilising it.Clr = RGB(m_bkR, m_bkG, m_bkB);
cheers --- -
Hello I was trying to debug this code (see below), because after a few minutes it crashes. So I used a
try{ }catch(...)
to catch the exception but I dont know what type of exception it was. Is there a way to tell? I tried usingTRY{} CATCH_ALL()
but it dod not catch anything??try{ DeleteObject(hbr); //must be deleted or eventually mem overflow hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC ) { CWnd *Ctrl = GetDlgItem(pWnd->GetDlgCtrlID()); if (Ctrl) { CRect Rect; Ctrl->GetWindowRect(&Rect); this->ScreenToClient(&Rect); COLORREF Clr = GetDC()->GetPixel(Rect.left-1, Rect.top-1); hbr = CreateSolidBrush(Clr); ASSERT(pDC); if(!m_staticTextBgd) pDC->SetBkColor(Clr); pDC->SetTextColor(RGB(m_fntR,m_fntG,m_fntB)); pDC->SetBkMode(m_staticTextBgd?OPAQUE:TRANSPARENT); } } } catch(...) { printf("Error"); }
I tried catching CResourceException and CMemoryException and many others but it did not catch anything? How do I know what exception is being thrown? ---There are a limited number of device contexts available at any one time. Every time this executes, you are locking one of these DCs with
GetDC()
but not releasing it withReleaseDC()
. Eventually, there will be no DCs available, andGetDC()
will returnNULL
. Since you're not doing any error checking, you'll get a NULL-pointer exception while trying to callGetPixel()
.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"