#1311 Exceptions thrown in one thread are caught in another

OTHER
closed
nobody
gcc (462)
rejected
User_Error
2014-08-14
2009-06-28
Doug Burns
No

Exceptions thrown in one thread are caught in another, whether there be a single thread & the main() running, or multiple threads + main(). In the example below, the second thread to be started catches the exception thrown by the first thread and the main(), with executing continuing after the catch in the second thread. Code runs correctly in VC++.

OS: Windows Xp SP3, using cmd.exe

Reading specs from c:/Mingw/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)

GNU ld version 2.15.91 20040725

CYGWIN_NT-5.1 doogie 1.5.11(0.116/4/2) 2004-09-04 23:17 i686 unknown unknown Cygwin

Build parameters:
g++ -c -o throwSpaz.o throwSpaz.cpp -I"C:/Mingw/include" -I"C:\Mingw\include\c++\3.4.5" -fexceptions
g++ -o throwSpaz.exe throwSpaz.o -fexceptions -L"C:/Mingw/lib" -mthread -s

file 'throwSpaz.cpp':
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

DWORD __stdcall threadFunc(void *myId)
{
while (1)
{
try
{
Sleep(1000);
cout << "TThrow threadFunc() {" << (int)myId << "} about to throw..." << endl;
throw "catch me!";
Sleep(1000);
}
catch (const char *x)
{
cout << "TCatch threadFunc() {" << (int)myId << "} Caught exception: " << x << endl;
}
}
}

int main(int argc, char *argv[])
{
CreateThread(0, 0, threadFunc, (void*)0, 0, 0);
Sleep(1);
CreateThread(0, 0, threadFunc, (void*)1, 0, 0);

while (1)
{
try
{
Sleep(5000);
cout << "MThrow main() about to throw..." << endl;
throw "catch this!";
Sleep(1000);
}
catch (const char *x)
{
cout << "MCatch main() Caught exception: " << x << endl;
}
}

system("PAUSE");
return EXIT_SUCCESS;
}

Discussion

  • Doug Burns

    Doug Burns - 2009-06-29

    Not a MinGW bug.

    Although your problem may be interesting and causing you problems you wish answers to, it is not a problem with the MinGW runtime,
    w32api, GCC, binutils or msys. Your BUG report has therefore been deleted. If you feel that this needs further discussion then
    please post to mingw-users@lists.sourceforge.net.

    Thanks for your interest in the MinGW Project,
    MinGW Project Administrators

     
  • Doug Burns

    Doug Burns - 2009-06-29

    Use -mthreads rather than -mthread in the link

     
  • Doug Burns

    Doug Burns - 2009-06-29
    • status: open --> closed-rejected
     
  • Earnie Boyd

    Earnie Boyd - 2013-01-25
    • status: closed-rejected --> closed
    • resolution: --> rejected
    • category: --> User_Error
    • milestone: --> OTHER
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks