---
schema_version: "1"
id: 44d6ad52425c00cd03392a4d706c87771087bfd51638694c2b2731f954546545
title: Error Handling
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/bot-api/einstein-bot/guides/sdk/sdk-error-handling.md
canonical_url: https://developer.salesforce.com/docs/service/einstein-bot-api/guide/sdk-error-handling.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 56df8379910cbd39bb3e937e4c935bba9c40359c60d07dbd30935403b5140fd9
products:
  - Einstein Bots API and SDK
  - Enstein Bot API and SDK
---
# Error Handling

If the bot API returns an error, the SDK wraps the error into a `ChatbotResponseException` object. This example shows how to retrieve the error details using `try` and `catch`.

```java
// Build the request to end the session.
BotEndSessionRequest botEndSessionRequest = BotRequest
    .withEndSession(EndSessionReason.USERREQUEST).build();

// Create an invalid session ID to return an error.
RuntimeSessionId invalidSessionId = new RuntimeSessionId("invalid session id");

// Send the request to end the session with error handling.
try{
    BotResponse endSessionResponse = client
        .endChatSession(config, invalidSessionId , botEndSessionRequest);
}catch (Exception e){

    // The error is wrapped in RuntimeException and ExecutionException.
    // Therefore, call getCause() twice to find the root cause.
    ChatbotResponseException chatbotResponseException =
        ((ChatbotResponseException)e.getCause().getCause());

    int httpStatusCode = chatbotResponseException.getStatus();

    System.out.println("Error Http Status Code : " + httpStatusCode);

    Error errorResponse = chatbotResponseException.getErrorResponse();
    System.out.println("Error Payload : " + errorResponse);
}
```
