Reworked implementation of custom error definition

Implementation has been reworked based on discussion from #280 and #221.
Passed implementation has been removed.