better exception handling mechanism for the API