Intermediate 25 min read

Common Runtime Exceptions and What They Really Mean

By the end of this lesson, you'll be able to:

  • Recognize NullPointerException, ListException, and DmlException by their typical message pattern
  • Translate an exception message directly into a likely root cause
  • Apply Module 13's exception types to real debugging scenarios

Prerequisites: "Checkpoints and the Developer Console Debugger"

NullPointerException: what the message actually tells you

System.NullPointerException: Attempt to de-reference a null object

Class.OpportunityTriggerHandler.afterUpdate: line 12, column 1

This message pattern — "Attempt to de-reference a null object" — always means code tried to call a method or access a field on something that was null. The stack trace beneath it (line 12) tells you exactly which line, and from there, the fix is almost always Module 12's null-check guard, added at that specific point.

ListException: what the message actually tells you

System.ListException: List index out of bounds: 5

"List index out of bounds: 5" means code accessed index 5 on a list that doesn't have that many elements — the number in the message is the index that was attempted, immediately narrowing the search to wherever that specific index came from (often an off-by-one mistake, Module 7's classic-for-loop trap).

DmlException: reading the real cause from the message

System.DmlException: Update failed. First exception on row 0;
first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,
An Opportunity cannot be marked Closed Won without a positive Amount.: []

A DmlException's message usually names the actual underlying reason — here, FIELD_CUSTOM_VALIDATION_EXCEPTION plus the exact custom message from Module 26's addError() call. Reading past the generic "Update failed" prefix to the specific reason underneath it is the key skill: the real cause is almost always spelled out directly in the message, not something to guess at.

Exercise

As a comment, translate this exception message into where you would look first: "System.ListException: List index out of bounds: 10".

Show hint

The number in the message is the specific index that was attempted.

APEX

Common Runtime Exceptions and What They Really Mean Quiz

1. What does a DmlException's message usually contain beyond the generic "Update failed" prefix?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

This lesson revisits Module 13's built-in exceptions from a debugging angle — translating a real error message directly into where to look first.