Add factories code (for both error and exception) and tests.