Resolved a thread safety issue that could generate warnings when defining error classes.

Fixes #454