Error management ++++++++++++++++ Overview ======== The Python Kortex API currently has only one mechanism to manage errors: surrounding the code block with a try/except statement pair and reacting to the exception. Note that there are :ref:`special cases ` explained at the end of this document. .. code-block:: python try: base_service.CreateUserProfile(Base_pb2.FullUserProfile()) except KClientException as ex: # Get error and sub error codes error_code = ex.get_error_code() sub_error_code = ex.get_error_sub_code() print("Error_code:{0} , Sub_error_code:{1} ".format(error_code, sub_error_code)) print("Caught expected error: {0}".format(ex)) except KServerException as server_ex: # Do something... except Exception: # Do something... A KClientException is thrown when an error occurs on the API client side, just as a KServerException is thrown when the error occurs on the API server side. A KClientException includes :class:`ErrorCodes ` and :class:`SubErrorCodes ` to describe the exception. Special case ============ This section describes a case that doesn't follow the standard error management rules documented earlier in this document. RouterClient ------------ When a RouterClient object is instantiated, a callback function (or lambda expression) can be specified. This function will be called if an exception is thrown during the process. .. code-block:: python router = RouterClient(transport, lambda kException: print("Error detected: {}".format(kException)))