# Displaying errors in LWC, Aura and Visualforce

*Platform Developer II Study Guide · User Interface · Last updated October 19, 2026 · https://www.certifyforce.com/study-guide/platform-developer-ii/user-interface/displaying-errors-in-lwc-aura-and-visualforce*

How a server or input error reaches the user: AuraHandledException instead of a stripped system exception, the different error.body shapes from Apex and Lightning Data Service, awaiting imperative calls, lightning-messages, lightning-input validity, toasts, apex:pageMessages with reRender, and how trigger addError messages surface.

- Certification: Salesforce Platform Developer II
- Exam section: User Interface
- Study guide: https://www.certifyforce.com/study-guide/platform-developer-ii

**Official exam objective:**

> Given a scenario, identify best practices for displaying errors in the user interface.

## What the exam expects

- Return a readable server error to Aura and LWC with `AuraHandledException`, and read it on the client.
- Read `error.body` correctly for Apex and for Lightning Data Service wire adapters, and catch errors from asynchronous calls.
- Pick the display: `lightning-messages` in a record edit form, field-level validity on `lightning-input`, a toast for page-level outcomes.
- Make Visualforce messages appear after a partial page update, and know where a trigger's `addError` message shows up.

Key terms: **`AuraHandledException`** (an exception whose message Apex chooses and the client receives), **`error.body`** (the response body on an LWC error, whose shape depends on the API), **`lightning-messages`** (the component that shows a record edit form's errors), **custom validity** (`setCustomValidity()` plus `reportValidity()` on an input), **`<apex:pageMessages>`** (Visualforce's display of all messages for the page).

How `addError` behaves inside triggers is owned by *Advanced trigger context and handler patterns*; this unit covers how messages reach the screen. The PD I basics are in the Platform Developer guide's *Apex for page components: controllers and wire adapters*.

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Unhandled system exception returned to Aura | Details stripped; shows "An internal server error has occurred" | [Returning Errors from Apex](https://developer.salesforce.com/docs/platform/aura-platform/guide/controllers-server-apex-custom-errors.html) |
| Aura error read | State ERROR; message in `response.getError()` | [Returning Errors from Apex](https://developer.salesforce.com/docs/platform/aura-platform/guide/controllers-server-apex-custom-errors.html) |
| `AuraHandledException` support | Aura and LWC; no `body.stackTrace` | [Handle Errors from Apex](https://developer.salesforce.com/docs/platform/lwc/guide/apex-error-handling.html) |
| `getRecord` error body | Array of objects | [Handle Errors in LDS](https://developer.salesforce.com/docs/platform/lwc/guide/data-error.html) |
| Apex error body | Object | [Handle Errors in LDS](https://developer.salesforce.com/docs/platform/lwc/guide/data-error.html) |
| `try/catch` | Catches synchronous code only; await the promise | [Handle Errors in LDS](https://developer.salesforce.com/docs/platform/lwc/guide/data-error.html) |
| `lightning-messages` | Before or after the input fields; no handler needed | [lightning-record-edit-form](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-record-edit-form.html?type=Develop) |
| Custom field error | `setCustomValidity()` then `reportValidity()`; `""` clears | [lightning-input](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-input.html?type=Develop) |
| Preferred toast | `lightning/toast` | [Toast Notifications](https://developer.salesforce.com/docs/platform/lwc/guide/use-toast.html) |
| Partial update scope | Only the identified components and their children | [Partial Page Updates](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-quick-start-ajax-partial-page-updates.html) |
| Field-level trigger error | `field.addError()` or `addError(fieldName, msg)` | [SObject Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm) |

## Check yourself

- Why does an unhandled `DmlException` give an Aura component's users a generic message?
- When is `error.body` an array rather than an object?
- Why can a `try/catch` miss an imperative Apex error?
- Where must `lightning-messages` go to show a record edit form's errors?

## Sources

- [Returning Errors from an Apex Server-Side Controller](https://developer.salesforce.com/docs/platform/aura-platform/guide/controllers-server-apex-custom-errors.html)
- [Handle Errors from Apex](https://developer.salesforce.com/docs/platform/lwc/guide/apex-error-handling.html)
- [Handle Errors in Lightning Data Service](https://developer.salesforce.com/docs/platform/lwc/guide/data-error.html)
- [Work with Errors](https://developer.salesforce.com/docs/platform/lwc/guide/data-error-types.html)
- [Call Apex Methods Imperatively](https://developer.salesforce.com/docs/platform/lwc/guide/apex-call-imperative.html)
- [lightning-record-edit-form](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-record-edit-form.html?type=Develop)
- [lightning-input](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-input.html?type=Develop)
- [Toast Notifications](https://developer.salesforce.com/docs/platform/lwc/guide/use-toast.html)
- [apex:pageMessages](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-pagemessages.html)
- [apex:pageMessage](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-pagemessage.html)
- [Implement Partial Page Updates with Command Links and Buttons](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-quick-start-ajax-partial-page-updates.html)
- [SObject Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit and reading progress are included in the full study guide. The separate practice exams option includes the reviewed question bank and timed mock exams. The bundle includes both where available. See [current options and prices](https://www.certifyforce.com/pricing).
