Salesforce Decode
Salesforcedecode
Back to questions
ApexBeginnerexceptionserror-handling

What is an Apex exception and basic error handling?

Real World Scenario

Users see a generic "Script-thrown exception" on save. You describe handling errors properly.

Expected Answer

• Exceptions stop transaction execution and roll back unless caught in try-catch • Use try-catch for expected failures like callout timeouts with user-friendly handling • Throw custom exceptions with clear messages for validation failures when appropriate • Log errors to custom object or platform logging for support teams—avoid exposing stack traces to users • Trigger exceptions block the save—message should help user fix data when possible

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

No. Over-catching hides bugs. Wrap risky callouts and parsing; let programming errors fail tests.

Architect Perspective

User-facing errors vs developer logs—split those in answers to show UX awareness.