Make exceptions-related global variables thread-local (closes #35)