Abstract API exception handling

Change-Id: I5017dfa60d4a8266908cc09c40b95139f01da0de