Menu

SEH?

Eu Genek
2009-01-15
2012-09-26
  • Eu Genek

    Eu Genek - 2009-01-15

    Hello,

    Ultimately, I'm trying to prevent the operating system (WIN XP) from terminating my program when my program does something silly. If someone has a nice example on how I can go about that, I'd appreciate it greatly.

    In my search for the answer I found the following I wanted to try. However, I am getting an " `_set_se_translator' undeclared " error.

    include <windows.h>

    include <iostream>

    struct SEHException
    {
    SEHException(const EXCEPTION_RECORD & record)
    : record(record)
    {}

    EXCEPTION_RECORD record;
    

    };

    void translator_function(unsigned int, EXCEPTION_POINTERS eps)
    {
    throw SEHException(
    eps->ExceptionRecord);
    }

    int main()
    {
    try
    {
    _set_se_translator(&translator_function);
    // stuff
    }
    catch (SEHException & e)
    {
    // handle the exception
    }
    return 0;
    }

    I have tried setting the "Enable Exception Handling" option under both project and compiler tabs. It didn't help.

    The compile log. I'm using Dev C++ 4.9.9.2.

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Main\Tools\Dev-Cpp\MyStuff\Tests\seh.cpp" -o "C:\Main\Tools\Dev-Cpp\MyStuff\Tests\seh.exe" -Werror -Wall -fexceptions -I"C:\Main\Tools\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Main\Tools\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Main\Tools\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Main\Tools\Dev-Cpp\include\c++\3.4.2" -I"C:\Main\Tools\Dev-Cpp\include" -I"C:\Main\Tools\Dev-Cpp\boost_1_34_0" -L"C:\Main\Tools\Dev-Cpp\lib"
    C:\Main\Tools\Dev-Cpp\MyStuff\Tests\seh.cpp:3:16: eh.h: No such file or directory
    C:\Main\Tools\Dev-Cpp\MyStuff\Tests\seh.cpp: In function int main()': C:\Main\Tools\Dev-Cpp\MyStuff\Tests\seh.cpp:23: error:_set_se_translator' undeclared (first use this function)
    C:\Main\Tools\Dev-Cpp\MyStuff\Tests\seh.cpp:23: error: (Each undeclared identifier is reported only once for each function it appears in.)

    Execution terminated

    Thanks.

     
    • Eu Genek

      Eu Genek - 2009-01-15

      Thanks Clifford,

      I eventually made it there. It took some time though. I was frustrated by snippets of code here and there which don't tell me which headers are required.

      Anyways, I don't have <eh.h> on my PC so I'll have to get that somewhere.

      I did, however, find another solution for my problem. This uses <csignal>, which I do have, and seems a little simpler than the above.

      include <csignal>

      void cleanUp( int dummy )
      {
      // Error recovery / cleanup code/ pseudo graceful exit.
      }

      int main()
      {

      // Connect various signals to our clean-up function
      signal( SIGSEGV, cleanUp);
      signal( SIGABRT, cleanUp);
      signal( SIGTERM, cleanUp );
      signal( SIGINT, cleanUp );
      
      // The above weren't catching Divide by Zero or Access Violation Errors
      // so I just did the following, which does.
      for ( unsigned int i = 0; i != 255; ++i)
      {
          signal(i, cleanUp);
      }
      
      
      // Some code to reproduce access violation error / divide by zero / etc...
      

      }

      Now, I just have to figure out why my program is crashing in the first place...

      Again, thanks for your time.

       
    • cpns

      cpns - 2009-01-15

      Well the code calls _set_se_translator() but there is no declaration for it. You have only included <windows.h> and <iostream> and it is not declared in either of those.

      The documentation ( http://msdn.microsoft.com/en-us/library/5z4bw5h5(VS.80).aspx ) clearly states <eh.h>. You read the documentation right?

      Clifford

       

Log in to post a comment.