---
schema_version: "1"
id: d3874ad69f5d7cbba2da2d5c684b98e5d098b2121eaff1721b786ce8630a1940
title: Handling Errors in Your Container
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/container/container-handling-errors.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/container-handling-errors.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6d2836d370a0bcc85ecc6cd6fcade9f53b6838b2a412eaeb2d01199ebf317320
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Handling Errors in Your Container

Handle errors in Lightning container with a method in your component’s controller.

This example uses the same code as the examples in [Using a Third-Party Framework](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-js.md#using-a-third-party-framework) and [Sending Messages from the Lightning Container Component](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-sending-messages.md#sending-messages-from-the-lightning-container-component).

In this component, the `onerror` attribute of `lightning:container` specifies `handleError` as the error handling method. To display the error, the component markup uses a conditional statement, and another attribute, `error`, for holding an error message.

```html
<aura:component access="global" implements="flexipage:availableForAllPageTypes" >
    
    <aura:attribute access="private" name="messageToSend" type="String" default=""/>
    <aura:attribute access="private" name="messageReceived" type="String" default=""/>
    <aura:attribute access="private" name="error" type="String" default=""/>
    
    <div>
        <lightning:input name="messageToSend" value="{!v.messageToSend}" label="Message to send to React app: "/><lightning:button label="Send" onclick="{!c.sendMessage}"/>
        
        <br/>
        
        <lightning:textarea name="messageReceived" value="{!v.messageReceived}" label="Message received from React app: "/>
        
        <br/>
        
        <aura:if isTrue="{! !empty(v.error)}">
            <lightning:textarea name="errorMessage" value="{!v.error}" label="Error: "/>
        </aura:if>
    
        <lightning:container aura:id="ReactApp"
                             src="{!$Resource.SendReceiveMessages + '/index.html'}"
                             onmessage="{!c.handleMessage}"
                             onerror="{!c.handleError}"/>
    </div>
    
</aura:component>

```

This is the component’s controller.

```javascript
({    
    sendMessage : function(component, event, helper) {
        
        var msg = {
            name: "General",
            value: component.get("v.messageToSend")
        };
        component.find("ReactApp").message(msg);
    },
    
    handleMessage: function(component, message, helper) {
        var payload = message.getParams().payload;
        var name = payload.name;
        if (name === "General") {
            var value = payload.value;
            component.set("v.messageReceived", value);
        }
        else if (name === "Foo") {
            // A different response
        }
    },
    
    handleError: function(component, error, helper) {
        var description = error.getParams().description;
        component.set("v.error", description);
    }
})
```

If the Lightning container application throws an error, the error handling function sets the `error` attribute. Then, in the component markup, the conditional expression checks if the error attribute is empty. If it isn’t, the component populates a `lightning:textarea` element with the error message stored in `error`.

**See Also**  


-   [Lightning Container](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-overview.md)
-   [Using a Third-Party Framework](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-js.md)
-   [Sending Messages from the Lightning Container Component](https://developer.salesforce.com/docs/platform/aura-platform/guide/container-sending-messages.md)

