Fix a bug related to thread creation and print more useful exceptions.