This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

about exception type issuse


Dear All

    I write the following code,and get the an unknow exception.Would any
body tell me what the exception is?why it can be catched by
catch(...),but can not be catched by user's code.

best,
Guanjun

code:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdexcept>
#include <ios>
#include <fstream>
#include <csignal>
#include <iostream>
#include <exception>
#include <exception_defines.h>
#include <unwind.h>
typedef unsigned _Unwind_Exception_Class
__attribute__((__mode__(__DI__)));

void *thread(void*)
{
        int i;
        pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);

pthread_setcanceltype(/*PTHREAD_CANCEL_ASYNCHRONOUS*/PTHREAD_CANCEL_DEFERRED, 0);
        try
        {
                for(i=0;/*i<3*/;i++) {
                        //pthread_testcancel();
                        printf("This is a pthread.\n");
                        //pthread_testcancel();
                }
        }catch(.../*_Unwind_Reason_Code &n*//*struct _Unwind_Exception
&b*//*_Unwind_Exception_Class &u*/)
        {
                printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^This
is the child thread: \n");/*%d .\n", n);*/
                //throw;
                //a.what();
                /*do nothing*/
        }
        return 0;
}

int main(void)
{
        pthread_t id;
        int ret;
        ret=pthread_create(&id,NULL, thread,NULL);
        if(ret!=0){
                printf ("Create pthread error!\n");
                exit (1);
        }
        usleep(100);
        printf("********************This is the main thread.\n");
        pthread_cancel(id);
        printf("********************This is the main thread.\n");
        //pthread_join(id,0);
        return (0);
}







Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]