This documentation is archived and is not being maintained.


Handles Win32 exceptions (C structured exceptions) as C++ typed exceptions.

_se_translator_function _set_se_translator(
   _se_translator_function se_trans_func 


Pointer to a C structured exception translator function that you write.

Return Value

Returns a pointer to the previous translator function registered by _set_se_translator, so that the previous function can be restored later. If no previous function has been set, the return value may be used to restore the default behavior; this value may be NULL.


The _set_se_translator function provides a way to handle Win32 exceptions (C structured exceptions) as C++ typed exceptions. To allow each C exception to be handled by a C++ catch handler, first define a C exception wrapper class that can be used, or derived from, to attribute a specific class type to a C exception. To use this class, install a custom C exception translator function that is called by the internal exception-handling mechanism each time a C exception is raised. Within your translator function, you can throw any typed exception that can be caught by a matching C++ catch handler.

Use /EHa instead of /EHsc when using _set_se_translator.

To specify a custom translation function, call _set_se_translator with the name of your translation function as its argument. The translator function that you write is called once for each function invocation on the stack that has try blocks. There is no default translator function.

In a multithreaded environment, translator functions are maintained separately for each thread. Each new thread needs to install its own translator function. Thus, each thread is in charge of its own translation handling. _set_se_translator is specific to one thread; another DLL can install a different translation function.

The se_trans_func function that you write must take an unsigned integer and a pointer to a Win32 _EXCEPTION_POINTERS structure as arguments. The arguments are the return values of calls to the Win32 API GetExceptionCode and GetExceptionInformation functions, respectively.

typedef void (*_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS* );

For _set_se_translator, there are implications when dynamically linking to the CRT; another DLL in the process may call _set_se_translator and replace your handler with its own.


Routine Required header Compatibility
_set_se_translator <eh.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_settrans.cpp
// compile with: /EHsc
#include <stdio.h>
#include <windows.h>
#include <eh.h>

void SEFunc();
void trans_func( unsigned int, EXCEPTION_POINTERS* );

class SE_Exception
    unsigned int nSE;
    SE_Exception() {}
    SE_Exception( unsigned int n ) : nSE( n ) {}
    ~SE_Exception() {}
    unsigned int getSeNumber() { return nSE; }
int main( void )
        _set_se_translator( trans_func );
    catch( SE_Exception e )
        printf( "Caught a __try exception with SE_Exception.\n" );
void SEFunc()
        int x, y=0;
        x = 5 / y;
        printf( "In finally\n" );
void trans_func( unsigned int u, EXCEPTION_POINTERS* pExp )
    printf( "In trans_func.\n" );
    throw SE_Exception();


In trans_func.
In finally
Caught a __try exception with SE_Exception.

See Also

Exception Handling Routines | set_terminate | set_unexpected | terminate | unexpected | Run-Time Routines and .NET Framework Equivalents