adding error code returns to relevant functions

Only for cpp - will do python later.