dpreznik 0 Light Poster

I have an MFC application. On the following line
MonoBuff = new short[iSize];
an exception is thrown that is caught in CATCH_ALL(e) block in wincore.cpp, getting "Warning: Uncaught exception in WindowProc".
It is said to be a CMemoryException. Surprisingly, when I tried to use try/catch block in my code, CMemoryException was not caught. I replaced it with catch(CException* ex), and caught it. Again, it is said to be CMemoryException.
Can anybody explain to me such a behavior? And maybe someone can give me an advice how to prevent this exception?
Here is a part of the code:

CString strWAVFile = GetWAVFilePath();

      short* MonoBuff = NULL;

      try
      {
//.... some other code
                  MonoBuff = new short[iSize];
//.... some other code
      }
      catch(WaveErrors::FileOperation & )
      {
            AfxMessageBox("File operation error!\n", MB_ICONSTOP);
            return;
      }
      catch(WaveErrors::RiffDoesntMatch & )
      {
            AfxMessageBox("Riff doesn't match!\n", MB_ICONSTOP);
            return;
      }
      catch(WaveErrors::WaveDoesntMatch & )
      {
            AfxMessageBox("Wave doesn't match!\n", MB_ICONSTOP);
            return;
      }
      catch(WaveErrors::DataDoesntMatch & )
      {
            AfxMessageBox("Data doesn't match!\n", MB_ICONSTOP);
            return;
      }
      catch(WaveErrors::FmtDoesntMatch & )
      {
            AfxMessageBox("Format doesn't match!\n", MB_ICONSTOP);
            return;
      }
      catch(WaveErrors::BextDoesntMatch & )
      {
            AfxMessageBox("BEXT Format doesn't match!\n", MB_ICONSTOP);
            return;
      }
      catch(CMemoryException* ex) // doesn't catch, but catches if replaced with CException
      {
            char msg[1000];
            ex->GetErrorMessage(msg, 1000);
            AfxMessageBox(msg);
      }

I debugged watching Mem Usage in Task Manager.

I noticed that after execution of
CString strWAVFile = GetWAVFilePath();
Mem Usage jumps from approximately 10MB to 14MB. It is not much, but after I replaced this line with hard coded path, it stays at 10MB, and what is more important, the execution passed the problematic line
MonoBuff = new short[iSize];
without problems, though Mem Usage became about 500MB, and later around 1GB.
So something wrong definitely happened in GetWAVFilePath();
I stepped into this function, and noticed that jump from 10MB to 14MB happens here:
CFileDialog ImpDlg(bOpen, NULL, "", bOpen ? NULL : OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL);

if (ImpDlg.DoModal() == IDOK) // it happens on opening the CFileDialog.

I am not sure what I can do about it now. Any suggestions?
Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.