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. Help With Exception

Help With Exception

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpc++visual-studiodata-structures
8 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    First I would like to start thanks to all on the CodeProject I think I am getting a little better at this (this being MFC) Well my code works fine Under the VS 2012 debugger, However When I rebuild it in Release mode. I get a message that my program stopped working with the option of invoking the VS debugger, which I do the code points to MFC code Unhandled Exception going back via the Call Stack it points to CString code Which I will gladly post, Well the Next thing I did seeing the code works fine in Debug mode, was code a CATCH_ALL exception handler just to see if the code with go to the CATCH_ALL block in Which I invoke AfxMessageBox(".... exception handler") and the message was displayed. I think at this point I have to get a little more specific (as to what type of exception) So at the point I think I'll post my code The Bold underline code seems be where the problem is when I go bank via the Call Stack In Debug mode I check the contents and tempstr is a Valid Null Terminated String Can someone at least point me to where I might be able find information exception to catch the specific exception that's giving me the problem Thanks

     if(pMsg->message==WM\_KEYDOWN)
    {
    	TRY
    	{
    	if(pMsg->wParam==VK\_RETURN)
    	{
    	//	DebugBreak();
    		main\_app = (CHERC\_CMDApp \*)AfxGetApp();
    		memcpy((void \*)main\_app->mybaseeventptr->command,(void \*)"REL",3);
          
    	memcpy((void \*)main\_app->threadptr\[curr\_thread\]->sockbuffer,(void \*)"REL",3);
    		main\_app->threadptr\[curr\_thread\]->num\_buff = 3;
    		**CString tempstr = PSW.ia**;
    		**tempstr.SetAt(16,0x00);
    		tempstr.MakeUpper();**
    			if(tempstr == end\_address)
    		{
    			memcpy((void \*)main\_app->threadptr\[curr\_thread\]->sockbuffer,(void \*)"TERM",4);
    		main\_app->threadptr\[curr\_thread\]->num\_buff = 4;
    			
    		}
    		::PostThreadMessage(main\_app->threadptr\[curr\_thread\]->m\_nThreadID,WM\_SEND\_SOCK\_MESS,22,(LPARAM) main\_app->mybaseeventptr->command);
    
    		::GetCaretPos(&mycursor);
    		mychar = myedit->CharFromPos(mycursor);
    		longchar = mychar;
    		cursorline = myedit->LineFromChar(longchar);
    		linelen = myedit->LineLength(cursorline);
    		linelen = 125;
    		linechar = myedit->LineIndex(cursorline);
    		myedit->GetLine(cursorline,currline.GetBufferSetLength(linelen +1),linelen);
    		buffptr = currline.GetBuffer(10);
    		
            myeventptr = main\_app->mybaseeventptr;
            strncpy((char \*)myeventptr->command,(char \*)&nu\_lls\[0\],5);  // single step
    		myeventptr->send\_window = this;
    
    L J 2 Replies Last reply
    0
    • F ForNow

      First I would like to start thanks to all on the CodeProject I think I am getting a little better at this (this being MFC) Well my code works fine Under the VS 2012 debugger, However When I rebuild it in Release mode. I get a message that my program stopped working with the option of invoking the VS debugger, which I do the code points to MFC code Unhandled Exception going back via the Call Stack it points to CString code Which I will gladly post, Well the Next thing I did seeing the code works fine in Debug mode, was code a CATCH_ALL exception handler just to see if the code with go to the CATCH_ALL block in Which I invoke AfxMessageBox(".... exception handler") and the message was displayed. I think at this point I have to get a little more specific (as to what type of exception) So at the point I think I'll post my code The Bold underline code seems be where the problem is when I go bank via the Call Stack In Debug mode I check the contents and tempstr is a Valid Null Terminated String Can someone at least point me to where I might be able find information exception to catch the specific exception that's giving me the problem Thanks

       if(pMsg->message==WM\_KEYDOWN)
      {
      	TRY
      	{
      	if(pMsg->wParam==VK\_RETURN)
      	{
      	//	DebugBreak();
      		main\_app = (CHERC\_CMDApp \*)AfxGetApp();
      		memcpy((void \*)main\_app->mybaseeventptr->command,(void \*)"REL",3);
            
      	memcpy((void \*)main\_app->threadptr\[curr\_thread\]->sockbuffer,(void \*)"REL",3);
      		main\_app->threadptr\[curr\_thread\]->num\_buff = 3;
      		**CString tempstr = PSW.ia**;
      		**tempstr.SetAt(16,0x00);
      		tempstr.MakeUpper();**
      			if(tempstr == end\_address)
      		{
      			memcpy((void \*)main\_app->threadptr\[curr\_thread\]->sockbuffer,(void \*)"TERM",4);
      		main\_app->threadptr\[curr\_thread\]->num\_buff = 4;
      			
      		}
      		::PostThreadMessage(main\_app->threadptr\[curr\_thread\]->m\_nThreadID,WM\_SEND\_SOCK\_MESS,22,(LPARAM) main\_app->mybaseeventptr->command);
      
      		::GetCaretPos(&mycursor);
      		mychar = myedit->CharFromPos(mycursor);
      		longchar = mychar;
      		cursorline = myedit->LineFromChar(longchar);
      		linelen = myedit->LineLength(cursorline);
      		linelen = 125;
      		linechar = myedit->LineIndex(cursorline);
      		myedit->GetLine(cursorline,currline.GetBufferSetLength(linelen +1),linelen);
      		buffptr = currline.GetBuffer(10);
      		
              myeventptr = main\_app->mybaseeventptr;
              strncpy((char \*)myeventptr->command,(char \*)&nu\_lls\[0\],5);  // single step
      		myeventptr->send\_window = this;
      
      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      The big difference for variables between DEBUG mode and RELEASE mode is stack variables aren't zeroed. The simple statement

      void SomeFunc (void){
      int i;

      }

      i is guaranteed to start as zero in DEBUG mode but could be literally anything in RELEASE mode. In the above if you need the variable to start as zero you need it.

      void SomeFunc (void){
      int i = 0;

      }

      Now you most likely have a structure or pointer variable you are assuming is zero but you have not explicitly set it in a local variable. Your code will then always work in DEBUG mode but almost never works in RELEASE mode.

      In vino veritas

      F 1 Reply Last reply
      0
      • L leon de boer

        The big difference for variables between DEBUG mode and RELEASE mode is stack variables aren't zeroed. The simple statement

        void SomeFunc (void){
        int i;

        }

        i is guaranteed to start as zero in DEBUG mode but could be literally anything in RELEASE mode. In the above if you need the variable to start as zero you need it.

        void SomeFunc (void){
        int i = 0;

        }

        Now you most likely have a structure or pointer variable you are assuming is zero but you have not explicitly set it in a local variable. Your code will then always work in DEBUG mode but almost never works in RELEASE mode.

        In vino veritas

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        How about in release mode I attach the debugger I try to stepping thru the code that's giving me a problem Thanks

        L 1 Reply Last reply
        0
        • F ForNow

          First I would like to start thanks to all on the CodeProject I think I am getting a little better at this (this being MFC) Well my code works fine Under the VS 2012 debugger, However When I rebuild it in Release mode. I get a message that my program stopped working with the option of invoking the VS debugger, which I do the code points to MFC code Unhandled Exception going back via the Call Stack it points to CString code Which I will gladly post, Well the Next thing I did seeing the code works fine in Debug mode, was code a CATCH_ALL exception handler just to see if the code with go to the CATCH_ALL block in Which I invoke AfxMessageBox(".... exception handler") and the message was displayed. I think at this point I have to get a little more specific (as to what type of exception) So at the point I think I'll post my code The Bold underline code seems be where the problem is when I go bank via the Call Stack In Debug mode I check the contents and tempstr is a Valid Null Terminated String Can someone at least point me to where I might be able find information exception to catch the specific exception that's giving me the problem Thanks

           if(pMsg->message==WM\_KEYDOWN)
          {
          	TRY
          	{
          	if(pMsg->wParam==VK\_RETURN)
          	{
          	//	DebugBreak();
          		main\_app = (CHERC\_CMDApp \*)AfxGetApp();
          		memcpy((void \*)main\_app->mybaseeventptr->command,(void \*)"REL",3);
                
          	memcpy((void \*)main\_app->threadptr\[curr\_thread\]->sockbuffer,(void \*)"REL",3);
          		main\_app->threadptr\[curr\_thread\]->num\_buff = 3;
          		**CString tempstr = PSW.ia**;
          		**tempstr.SetAt(16,0x00);
          		tempstr.MakeUpper();**
          			if(tempstr == end\_address)
          		{
          			memcpy((void \*)main\_app->threadptr\[curr\_thread\]->sockbuffer,(void \*)"TERM",4);
          		main\_app->threadptr\[curr\_thread\]->num\_buff = 4;
          			
          		}
          		::PostThreadMessage(main\_app->threadptr\[curr\_thread\]->m\_nThreadID,WM\_SEND\_SOCK\_MESS,22,(LPARAM) main\_app->mybaseeventptr->command);
          
          		::GetCaretPos(&mycursor);
          		mychar = myedit->CharFromPos(mycursor);
          		longchar = mychar;
          		cursorline = myedit->LineFromChar(longchar);
          		linelen = myedit->LineLength(cursorline);
          		linelen = 125;
          		linechar = myedit->LineIndex(cursorline);
          		myedit->GetLine(cursorline,currline.GetBufferSetLength(linelen +1),linelen);
          		buffptr = currline.GetBuffer(10);
          		
                  myeventptr = main\_app->mybaseeventptr;
                  strncpy((char \*)myeventptr->command,(char \*)&nu\_lls\[0\],5);  // single step
          		myeventptr->send\_window = this;
          
          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          MFC throws exceptions derived from the CException class which contain additional information and provide a function to show a message. So you may add this block of code on front of your CATCH_ALL block:

          CATCH(CException, pEx)
          {
          pEx->ReportError();
          pEx->Delete();
          }

          The operation that might fail in your code is CString::SetAt (when the position is beyond the end of the string). This will throw an exception in release builds and assert with debug builds. Because you are not getting an assertion with a debug build, the only reason for an exception in release builds can be a different (shorter) PSW.ia string. If this is not the case the exception source is probably somewhere else. To avoid such out of range acesses you should check the length or use a function that handles them like CString::Left.

          F 2 Replies Last reply
          0
          • F ForNow

            How about in release mode I attach the debugger I try to stepping thru the code that's giving me a problem Thanks

            L Offline
            L Offline
            leon de boer
            wrote on last edited by
            #5

            Also turn your error level to 4 in release mode and look for any warning along the lines possible use of uninitialized variable.

            In vino veritas

            1 Reply Last reply
            0
            • J Jochen Arndt

              MFC throws exceptions derived from the CException class which contain additional information and provide a function to show a message. So you may add this block of code on front of your CATCH_ALL block:

              CATCH(CException, pEx)
              {
              pEx->ReportError();
              pEx->Delete();
              }

              The operation that might fail in your code is CString::SetAt (when the position is beyond the end of the string). This will throw an exception in release builds and assert with debug builds. Because you are not getting an assertion with a debug build, the only reason for an exception in release builds can be a different (shorter) PSW.ia string. If this is not the case the exception source is probably somewhere else. To avoid such out of range acesses you should check the length or use a function that handles them like CString::Left.

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              How about pEX->GetErrorMessage..... I think ReportError is just a message box with out any information ?

              J 1 Reply Last reply
              0
              • F ForNow

                How about pEX->GetErrorMessage..... I think ReportError is just a message box with out any information ?

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                I must confess that I have not tested if the reporting contains the error message but assumed that it would do so. But you can of course use GetErrorMessage with your own reporting.

                1 Reply Last reply
                0
                • J Jochen Arndt

                  MFC throws exceptions derived from the CException class which contain additional information and provide a function to show a message. So you may add this block of code on front of your CATCH_ALL block:

                  CATCH(CException, pEx)
                  {
                  pEx->ReportError();
                  pEx->Delete();
                  }

                  The operation that might fail in your code is CString::SetAt (when the position is beyond the end of the string). This will throw an exception in release builds and assert with debug builds. Because you are not getting an assertion with a debug build, the only reason for an exception in release builds can be a different (shorter) PSW.ia string. If this is not the case the exception source is probably somewhere else. To avoid such out of range acesses you should check the length or use a function that handles them like CString::Left.

                  F Offline
                  F Offline
                  ForNow
                  wrote on last edited by
                  #8

                  it was the SetAt Truthfully I never called the constructer so CString tempstr(&PSW.ia,16); Thanks

                  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