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. Exception problem

Exception problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++debuggingperformancehelp
7 Posts 5 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.
  • R Offline
    R Offline
    rrrado
    wrote on last edited by
    #1

    I'm not expert on exceptions. I need to catch some memory exception and ignore it, but it des not work. It only works in debug release (exception is ignored), but in release mode it crashes like when I don't handle the exception. What is the problem? Here is code :

    			try
    			{
    
    				\*((char\*)0)=1;
    			}
    			catch(...)
    			{
    			}
    

    It is MFC app in VC6.0. Thank you.

    D S L 3 Replies Last reply
    0
    • R rrrado

      I'm not expert on exceptions. I need to catch some memory exception and ignore it, but it des not work. It only works in debug release (exception is ignored), but in release mode it crashes like when I don't handle the exception. What is the problem? Here is code :

      			try
      			{
      
      				\*((char\*)0)=1;
      			}
      			catch(...)
      			{
      			}
      

      It is MFC app in VC6.0. Thank you.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      This is the difference between C++ typed exceptions and Win32 structured exceptions. What you have is the former. See _set_se_translator() for more.

      "Love people and use things, not love things and use people." - Unknown

      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

      R 1 Reply Last reply
      0
      • D David Crow

        This is the difference between C++ typed exceptions and Win32 structured exceptions. What you have is the former. See _set_se_translator() for more.

        "Love people and use things, not love things and use people." - Unknown

        "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

        R Offline
        R Offline
        rrrado
        wrote on last edited by
        #3

        Thank you. I'm going to check it. I wonder why debug mode caught the exception. Does debug mode use some default translator?

        D R 2 Replies Last reply
        0
        • R rrrado

          Thank you. I'm going to check it. I wonder why debug mode caught the exception. Does debug mode use some default translator?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          rrrado wrote:

          I wonder why debug mode caught the exception.

          I'm really not sure, but it may have to do with the optimizer.

          "Love people and use things, not love things and use people." - Unknown

          "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

          1 Reply Last reply
          0
          • R rrrado

            I'm not expert on exceptions. I need to catch some memory exception and ignore it, but it des not work. It only works in debug release (exception is ignored), but in release mode it crashes like when I don't handle the exception. What is the problem? Here is code :

            			try
            			{
            
            				\*((char\*)0)=1;
            			}
            			catch(...)
            			{
            			}
            

            It is MFC app in VC6.0. Thank you.

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            In C++ - assuming the implementation follows the standard - catch is only allowed to catch exceptions raised using the throw keyword: since this isn't the case in your example the code in the catch block should NOT be executed. MSVC6 got this wrong but the bug has been corrected in later versions. The /EH[^] switch can be used to reinstate the bug.

            Steve

            1 Reply Last reply
            0
            • R rrrado

              I'm not expert on exceptions. I need to catch some memory exception and ignore it, but it des not work. It only works in debug release (exception is ignored), but in release mode it crashes like when I don't handle the exception. What is the problem? Here is code :

              			try
              			{
              
              				\*((char\*)0)=1;
              			}
              			catch(...)
              			{
              			}
              

              It is MFC app in VC6.0. Thank you.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You can use an exception handler to ignore the access violation like this:

              __try
              {
              	*((char*)0)=1;
              }
              __except(EXCEPTION_EXECUTE_HANDLER)
              {
              }
              

              http://msdn.microsoft.com/en-us/library/ms681409(VS.85).aspx[^] Best Wishes, -David Delaune

              1 Reply Last reply
              0
              • R rrrado

                Thank you. I'm going to check it. I wonder why debug mode caught the exception. Does debug mode use some default translator?

                R Offline
                R Offline
                Rajkumar R
                wrote on last edited by
                #7

                rrrado wrote:

                I wonder why debug mode caught the exception

                Might be because you set the "Enable C++ Exception=> YES with Structured exception (/EHa)" for debug configuration settings but not for release configuration.

                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