This is using exceptions for flow control. Use a separate sync object to signal the thread to quit.