Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CATCH_ALL and OnCtlColor

CATCH_ALL and OnCtlColor

Scheduled Pinned Locked Moved C / C++ / MFC
questiondotnetdebugginghelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Coremn
    wrote on last edited by
    #1

    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 using TRY{} 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? ---

    M C R 3 Replies Last reply
    0
    • C Coremn

      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 using TRY{} 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? ---

      M Offline
      M Offline
      monrobot13
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • M monrobot13

        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

        C Offline
        C Offline
        Coremn
        wrote on last edited by
        #3

        First thing I tried, it seems it does not throw a CException at all. I am sure it is a memory resource overflow problem, even though I am deleting my HBRUSH object. ---

        1 Reply Last reply
        0
        • C Coremn

          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 using TRY{} 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? ---

          C Offline
          C Offline
          Coremn
          wrote on last edited by
          #4

          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 ---

          1 Reply Last reply
          0
          • C Coremn

            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 using TRY{} 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? ---

            R Offline
            R Offline
            Ryan Binns
            wrote on last edited by
            #5

            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 with ReleaseDC(). Eventually, there will be no DCs available, and GetDC() will return NULL. Since you're not doing any error checking, you'll get a NULL-pointer exception while trying to call GetPixel().

            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"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups