Boost logo

Boost :

From: Lee Brown (lee_at_[hidden])
Date: 2002-01-18 10:26:16


On Friday 18 January 2002 06:54, you wrote:
> --- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> > ----- Original Message -----
> > From: "terekhov" <terekhov_at_d...>
> >
> > > > > Yes, it should; but you should always re-"throw"
> > > > > unless you're really sure you want to break the
> > > > > entire world. I think that should ALWAYS be true
> > > > > for an anonymous catch(...), though. If you don't
> > > > > know what it is, you can't "finalize" the exception
> > > > > recovery, and you need to just clean up your own
> > > > > local context and let someone else further down
> > > > > handle it.
> > > >
> > > > Sometimes there is nobody further down, as we've seen.
> > >
> > > And process terminates and that is GOOD.
> >
> > Not really. Sometimes, for example at a 'C' API boundary, you
>
> simply have to
>
> > use catch(...) so you can prevent an exception from crashing your
>
> caller.

Maybe the user should decide on what behavior is best.

template<bool ThrowsExceptions>
void start_thread(function0 func) { func.run(); }

template<>
void start_thread<true> {
        try {
                func.run();
        }
        catch (...) { } //never propagates
};

template<CanclePolicy>
void cancel_thread(Thread t) { CancelPolicy::cancel(t); }

template<CancelPolicy>void test_cancel() {
        CancelPolicy::test_cancel();
};

struct throw_cancel {
        static void test_cancel() {
                if( flag.this_thread() == CANCELED ) throw EThreadCanceled();
        }
        static void cancel(thread t) { flag.this_thread = CANCELED; }

        static thread_specific_flag flag;
};

struct immediate_cancel {
        static void test_cancel() { pthread_test_cancel(); }
        static void cancel(thread t) { pthread_cancel(t); }
};


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk