cpp: Use proper error codes in exceptions

Change-Id: I956f909efe882cf9549cd367a2fa985e1cd7efd5