Make exception throwing work in threads