What is throwable

Sean Kelly sean at invisibleduck.org
Thu Mar 19 14:13:46 PDT 2009


== Quote from Sergey Gromov (snake.scaly at gmail.com)'s article
> Thu, 19 Mar 2009 20:44:51 +0000 (UTC), Sean Kelly wrote:
> >
> > I've considered letting the user supply a custom "unhandled
> > exception" handler for threads.  It just seemed messy given that
> > calling join() on a thread now will rethrow the unhandled exception
> > if there was one.  I figured that the user would join threads he cared
> > about, and if one he didn't care about terminated unexpectedly the
> > perhaps that's not a problem.
> The problem is when you have a worker thread which never terminates and
> sends notifications to the main thread.  Like game logic thread versus
> main GUI thread.  If logic thread throws, your game suddenly stops
> working for no apparent reason.

So wrap your logic in a try/catch:

void worker() {
    try {
        doStuff();
    } catch( Throwable t ) {
        notifyProgramOfFailure( t );
    }
}

auto t = new Thread( &worker );

I think a case could be made for simply terminating the
app on an unhandled exception in a thread, but logic
errors are the programmer's responsibility.



More information about the Digitalmars-d mailing list