1.5.18 Tracing and Debugging Returned Values

Last Updated: 9/21/2026
A Returned Value Moves from the Called Method Back to the Caller

Consider:

public int GetScore()
{
    return this.score;
}

and:

int currentScore = team1.GetScore();

The runtime flow is:

caller
  ↓
GetScore()
  ↓
return this.score
  ↑
caller receives result
  ↓
currentScore

The debugger can help you observe each stage.

Pause at the Method Call

Set a breakpoint before:

int currentScore = team1.GetScore();

Inspect:

team1

and predict:

If:

team1.score = 3

predict:

returned value = 3
Step Into the Returning Method

Use Step Into at:

team1.GetScore()

Inside the method, inspect:

this.score

Suppose the debugger shows:

3

Now the return statement:

return this.score;

should send 3 back to the caller.

Watch the Call Stack

While paused inside GetScore(), the Call Stack shows:

GetScore()
caller

The caller is waiting for the method to finish.

After the return executes, GetScore() leaves the active call stack and execution resumes in the caller.

Inspect the Local Variable After the Call

After the call completes:

int currentScore = team1.GetScore();

inspect:

currentScore

It should contain the value returned by the method.

For this example:

currentScore = 3

That completes the return-value trace.

Trace a Returned Calculation

Suppose:

public int GetTotalGoals()
{
    return this.homeGoals + this.awayGoals;
}

If the debugger shows:

homeGoals = 2
awayGoals = 1

predict:

2 + 1 = 3

Then step through and inspect the receiving variable after the call.

Trace a Conditional Return

Suppose:

public string GetAvailabilityText()
{
    if (this.isAvailable)
    {
        return "Available";
    }
    else
    {
        return "Unavailable";
    }
}

First inspect:

this.isAvailable

Then predict which return statement should execute.

For:

isAvailable = false

predict:

return "Unavailable";

Step through the condition and verify the selected return.

Separate the Source Expression from the Received Value

Inside the method, the source may say:

return this.score;

The caller receives the current value of that expression, such as:

3

The caller does not receive the source text:

this.score

It receives the value produced during execution.

Distinguish a Wrong Return from a Wrong Receiver Variable

Suppose the method correctly returns:

3

but later the caller changes:

currentScore

The return itself may be correct even though later program behavior becomes wrong.

Use the debugger to identify exactly when the unexpected value first appears.

Trace Parameters That Affect the Returned Result

Suppose:

public string GetGoalCategory(int goals)
{
    if (goals >= 3)
    {
        return "High scoring";
    }

    return "Fewer than three";
}

A call:

string category = team1.GetGoalCategory(4);

can be traced as:

argument 4
   ↓
parameter goals = 4
   ↓
goals >= 3 → true
   ↓
return "High scoring"
   ↓
category = "High scoring"

The debugger lets you verify that entire path.

Build a Runtime Explanation

A strong explanation is:

That describes evidence rather than guessing.

Key Trace
  1. Predict the result at the call site.
  2. Step into the returning method.
  3. Inspect the values used by the return expression.
  4. Identify the return statement reached.
  5. Step back to the caller.
  6. Inspect the receiving variable.
  7. Compare the observed value with the requirement.