1e04b953eSDavid Xu /* try to catch thread exiting, and rethrow the exception */ 2e04b953eSDavid Xu 3e04b953eSDavid Xu #include <pthread.h> 4e04b953eSDavid Xu #include <stdio.h> 5e04b953eSDavid Xu #include <stdlib.h> 6e04b953eSDavid Xu 7*ef135466SEd Maste static int caught; 8e04b953eSDavid Xu 9*ef135466SEd Maste static void * thr_routine(void * arg __unused)10*ef135466SEd Mastethr_routine(void *arg __unused) 11e04b953eSDavid Xu { 12e04b953eSDavid Xu try { 13e04b953eSDavid Xu pthread_exit(NULL); 14e04b953eSDavid Xu } catch (...) { 15e04b953eSDavid Xu caught = 1; 16e04b953eSDavid Xu printf("thread exiting exception caught\n"); 17e04b953eSDavid Xu /* rethrow */ 18e04b953eSDavid Xu throw; 19e04b953eSDavid Xu } 20e04b953eSDavid Xu } 21e04b953eSDavid Xu 22e04b953eSDavid Xu int main()23e04b953eSDavid Xumain() 24e04b953eSDavid Xu { 25e04b953eSDavid Xu pthread_t td; 26e04b953eSDavid Xu 27e04b953eSDavid Xu pthread_create(&td, NULL, thr_routine, NULL); 28e04b953eSDavid Xu pthread_join(td, NULL); 29e04b953eSDavid Xu if (caught) 30e04b953eSDavid Xu printf("OK\n"); 31e04b953eSDavid Xu else 32e04b953eSDavid Xu printf("failure\n"); 33e04b953eSDavid Xu return (0); 34e04b953eSDavid Xu } 35