Clean up error object creation and throwing functions.