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. SEH problem in release mode

SEH problem in release mode

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpannouncement
3 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.
  • R Offline
    R Offline
    Robin
    wrote on last edited by
    #1

    Just to let u know.. There seems to be a problem with SEH raising exceptions in release mode (using VC++ 6 SP4) In release mode, a divide by zero does not raise any exceptions but it does in debug mode. However, if I uncomment the cout line after the divide (in release mode), an exception would be raised. If the program was compile with the /EHa option (asynchronous exception), then an exception is always raised. I didn't do an disassembly but it's probably due to the compiler not generating the divide code since it's not used. [source] #include < windows.h > #include < iostream > #include < stdexcept > using namespace std; void SEH_Translator( unsigned int u, EXCEPTION_POINTERS* pExp ) { throw exception("SEH exception"); } void main() { try { _set_se_translator(SEH_Translator); int x,y; x = 9999; y = 0; int z = x/y; // cause a divide by zero exception // cout << z << endl; // uncommenting this throws an exception in release mode } catch(...) { cout << "Exception caught" << endl; } } [/source]

    F J 2 Replies Last reply
    0
    • R Robin

      Just to let u know.. There seems to be a problem with SEH raising exceptions in release mode (using VC++ 6 SP4) In release mode, a divide by zero does not raise any exceptions but it does in debug mode. However, if I uncomment the cout line after the divide (in release mode), an exception would be raised. If the program was compile with the /EHa option (asynchronous exception), then an exception is always raised. I didn't do an disassembly but it's probably due to the compiler not generating the divide code since it's not used. [source] #include < windows.h > #include < iostream > #include < stdexcept > using namespace std; void SEH_Translator( unsigned int u, EXCEPTION_POINTERS* pExp ) { throw exception("SEH exception"); } void main() { try { _set_se_translator(SEH_Translator); int x,y; x = 9999; y = 0; int z = x/y; // cause a divide by zero exception // cout << z << endl; // uncommenting this throws an exception in release mode } catch(...) { cout << "Exception caught" << endl; } } [/source]

      F Offline
      F Offline
      Feng Yuan
      wrote on last edited by
      #2

      As you said, compiler optimization in release mode may have removed the divide-by-zero.

      1 Reply Last reply
      0
      • R Robin

        Just to let u know.. There seems to be a problem with SEH raising exceptions in release mode (using VC++ 6 SP4) In release mode, a divide by zero does not raise any exceptions but it does in debug mode. However, if I uncomment the cout line after the divide (in release mode), an exception would be raised. If the program was compile with the /EHa option (asynchronous exception), then an exception is always raised. I didn't do an disassembly but it's probably due to the compiler not generating the divide code since it's not used. [source] #include < windows.h > #include < iostream > #include < stdexcept > using namespace std; void SEH_Translator( unsigned int u, EXCEPTION_POINTERS* pExp ) { throw exception("SEH exception"); } void main() { try { _set_se_translator(SEH_Translator); int x,y; x = 9999; y = 0; int z = x/y; // cause a divide by zero exception // cout << z << endl; // uncommenting this throws an exception in release mode } catch(...) { cout << "Exception caught" << endl; } } [/source]

        J Offline
        J Offline
        JoeBloggs
        wrote on last edited by
        #3

        The reason that an exception doesn't occur in this code in release is because the optimizer will throw all the code away as it does nothing... As soon as you include the cout z has to around so a value can be displayed hence the exception - In a debug build no code is optimized hence you get the behaviour expected.

        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