Error Handling

For the sake of clarity, most examples in the documentation do not fully demonstrate how to handle errors, preferring instead to focus on the topic at hand. However, the Diatheke SDK does report errors, and calling applications should be prepared to handle them.

A description of how errors are handled for each language is given below.


The C++ SDK uses exceptions to report errors. Errors originating from the SDK will have the class type Diatheke::ClientError, which inherits from the std::exception class. To handle these errors, simply create a try-catch block around the SDK code. For example:

    // Call SDK functions in here. The function calls may be in this
    // try block, or within functions that the try block calls.
catch (const Diatheke::ClientError &err)
    // Handle the error here. The specific error message can be
    // retrieved using err.what().


The Go SDK uses the built-in error type to return errors from functions (see here for general information about handling errors in Go). Most SDK functions will return an error in addition to their other return values. For example:

// Create a new client connection
client, err := diatheke.NewClient("")
if err != nil {
    // Handle the error here.


The Python SDK uses built-in exceptions to report errors. They can be handled by wrapping the client code in a try … except statement. For example:

    # Call SDK functions in here. The SDK functions may be
    # called directly, or within other functions that this
    # block eventually calls.

except BaseException as err:
    # Handle the error here. To have better control over how
    # individual errors are handled, you may use more concrete
    # exception types in the except statement.

    # Do any final cleanup here.


In the Swift SDK every method that can throw an error has DiathekeFailureCallback completion handler to report errors. For example:

client.createSession(modelID: { (sessionOutput) in
    // Handle success response here
} failure: { (error) in
    // Handle the error here


For synchronous calls, Java Exceptions are thrown by the generated gRPC calls, allowing the use of Try Catch blocks.

try {
    SessionStart req = SessionStart.newBuilder().setModelId(modelId).build();
    SessionOutput resp = mDiathekeBlockingService.createSession(req);
} catch (StatusRuntimeException e) {
    // Handle errors here

For asynchronous calls, the StreamObservers will include an onError callback method.

// Create the callback observer
StreamObserver<ASRResult> responseObserver = new StreamObserver<ASRResult>() {
    public void onNext(ASRResult result) {

    public void onError(Throwable t) {
        // Handle errors here

    public void onCompleted() {

// Create stream
StreamObserver<ASRInput> requestObserver = mDiathekeService.streamASR(responseObserver);

// Send data