Listing 4 Globally replacing an exception
#include <windows.h> #include <vector> #include <iostream> const DWORD CPP_EXCEPTION = 0xE06D7363; const DWORD MS_MAGIC = 0x19930520; extern "C" void __stdcall _CxxThrowException(void * pObject, _s__ThrowInfo const * pObjectInfo) { try { const ULONG_PTR args[] ={ MS_MAGIC, (ULONG_PTR)pObject, (ULONG_PTR)pObjectInfo }; RaiseException(CPP_EXCEPTION, EXCEPTION_NONCONTINUABLE, sizeof(args)/sizeof(args[0]), args); } catch(std::exception & ) { throw int(1); } } int main() { try { std::vector<char> x; x.at(100) = 'a'; } catch(int i) { std::cout << i; } return 0; }