# Displaying errors in LWC, Aura and Visualforce

*Platform Developer II Study Guide · User Interface · Last updated October 16, 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/atlas.en-us.lightning.meta/lightning/controllers_server_apex_custom_errors.htm) |
| Aura error read | State ERROR; message in `response.getError()` | [Returning Errors from Apex](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_custom_errors.htm) |
| `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/component-library/bundle/lightning-record-edit-form/documentation) |
| Custom field error | `setCustomValidity()` then `reportValidity()`; `""` clears | [lightning-input](https://developer.salesforce.com/docs/component-library/bundle/lightning-input/documentation) |
| 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/atlas.en-us.pages.meta/pages/pages_quick_start_ajax_partial_page_updates.htm) |
| 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/atlas.en-us.lightning.meta/lightning/controllers_server_apex_custom_errors.htm)
- [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/component-library/bundle/lightning-record-edit-form/documentation)
- [lightning-input](https://developer.salesforce.com/docs/component-library/bundle/lightning-input/documentation)
- [Toast Notifications](https://developer.salesforce.com/docs/platform/lwc/guide/use-toast.html)
- [apex:pageMessages](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageMessages.htm)
- [apex:pageMessage](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageMessage.htm)
- [Implement Partial Page Updates with Command Links and Buttons](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_ajax_partial_page_updates.htm)
- [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, its 7 linked practice questions, and unlimited timed mock exams are included with the Platform Developer II pack (USD $19): https://www.certifyforce.com/practice-exams
