catch and log exceptions occurring in threads