PDII practice question 4 of 10
A user receives the generic "An internal server error has occurred” while interacting with a custom Lightning component. What should the developer do to ensure a more meaningful message?
Full set: 198 questionsWhen an unhandled exception is thrown in an Apex controller method called by a Lightning component (LWC or Aura), the Salesforce framework obscures the original error details and returns a generic "An internal server error has occurred" message to the client for structural security. To provide a meaningful, user-friendly error message, the developer must encapsulate the Apex logic within a try-catch block, catch the original exception, and explicitly throw an AuraHandledException. The AuraHandledException is specifically designed to safely bypass the framework's default obscuration in Lightning component contexts. By instantiating an AuraHandledException with a custom message string, the developer ensures that the client-side JavaScript can access and gracefully display the precise error details to the end-user.
Option A: Adding an onerror event handler to an HTML tag only handles standard DOM/client-side errors, but it does not unmask server-side generic internal server errors sent by Apex.
Option B: Adding an error-view component simply changes the UI layout or presentation; it does not resolve the framework's suppression of the server-side message detailing the actual Apex failure.
Option C: While platform events are powerful for asynchronous publish/subscribe messaging, they are unnecessarily complex for this synchronous client-server transaction and do not directly return a readable server message to the component.
Salesforce Lightning Web Components Developer Guide: "Handle Server Errors", Section: Call Apex Methods.
Salesforce Aura Components Developer Guide: "Returning Errors from an Apex Server-Side Controller", Section: Apex Controllers.
Keep practicing
Take the free PDII practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PDII practice questions
- Question 3Which three Visualforce components can be used to initiate Ajax behavior to perform parti…
- Question 5A developer is asked to develop a new AppFxchange application. A feature of the program c…
- Question 7Universal Containers implements a private sharing model for the Convention Attendee co cu…
- Question 8Universal Containers develops a Visualforce page that requires the inclusion of external …
- Question 9A developer is trying to access org data from within a test class. Which sObject type req…
- Question 10A company has a Lightning page with many Lightning Components, some that cache reference …
