github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/runtime/testdata/testwinlibthrow/veh.cpp (about) 1 //go:build ignore 2 3 #include <windows.h> 4 5 extern "C" __declspec(dllexport) 6 void RaiseExcept(void) 7 { 8 try 9 { 10 RaiseException(42, 0, 0, 0); 11 } 12 catch (...) 13 { 14 } 15 } 16 17 extern "C" __declspec(dllexport) 18 void RaiseNoExcept(void) 19 { 20 RaiseException(42, 0, 0, 0); 21 } 22 23 static DWORD WINAPI ThreadRaiser(void* Context) 24 { 25 if (Context) 26 RaiseExcept(); 27 else 28 RaiseNoExcept(); 29 return 0; 30 } 31 32 static void ThreadRaiseXxx(int except) 33 { 34 static int dummy; 35 HANDLE thread = CreateThread(0, 0, ThreadRaiser, except ? &dummy : 0, 0, 0); 36 if (0 != thread) 37 { 38 WaitForSingleObject(thread, INFINITE); 39 CloseHandle(thread); 40 } 41 } 42 43 extern "C" __declspec(dllexport) 44 void ThreadRaiseExcept(void) 45 { 46 ThreadRaiseXxx(1); 47 } 48 49 extern "C" __declspec(dllexport) 50 void ThreadRaiseNoExcept(void) 51 { 52 ThreadRaiseXxx(0); 53 }