A C# program can build successfully and still encounter a problem during execution.
C# represents many runtime problems using exceptions.
An exception tells you that the program reached a situation it could not continue through normally.
At this stage, the goal is to recognize and diagnose an exception.
You are not yet learning full exception-handling design.
The compiler cannot successfully translate the current source.
Example idea:
player1.jerseyNumber = "seven";
when jerseyNumber expects an int.
The source built, the program started, and a problem occurred while a statement executed.
Example idea:
player1.team.name
when:
player1.team = null
The code is syntactically meaningful.
The runtime state makes the operation impossible.
C# exceptions have types that help describe what kind of runtime problem occurred.
In Module 1.1, the important example is:
NullReferenceException
Later programming modules introduce other exception types in more depth.
For now, use the exception type as diagnostic evidence.
When debugging, Visual Studio can stop near the statement where the exception occurred.
That gives you a useful investigation point.
Ask:
Do not immediately rewrite the whole method or class.
Use the paused state.
An exception can provide:
Read the type and message before changing code.
A message is not always a complete explanation of the underlying design problem, but it narrows the investigation.
Consider:
team1.name
If team1 refers to a Team object, the member access can work.
If:
team1 = null
then the same source statement can fail at runtime.
The source text did not change.
The runtime state did.
This is why debugger observation matters.
Suppose the program displays:
Jordan
when the requirement expected:
Casey
The program may run without throwing an exception.
That is still a behavioral error.
An exception is one kind of failure signal, not the only way software can be wrong.
If a statement throws an exception, commenting it out may make the program continue.
That does not automatically solve the requirement.
The removed line may represent required behavior.
In CO-029, you will use temporary commenting as a diagnostic technique while keeping the difference between:
temporary investigation
and:
actual correction
clear.
A useful exception workflow is:
Detailed try/catch, throwing exceptions intentionally, and exception propagation belong to later programming instruction.
An exception tells you:
The program built, but the current runtime operation failed.
Treat the exception as evidence about:
CO-029 applies that reasoning to one of the most common beginner exceptions: NullReferenceException.