1.3.1 Common Exception Types

Exception Types Describe Different Runtime Problems

You already encountered:

Plain text
NullReferenceException

when code tried to use an object member through null.

C# and .NET define many exception types so runtime failures can communicate different categories of problems.

At this stage, the goal is recognition and diagnosis—not writing try/catch logic.

NullReferenceException

This occurs when code attempts to use an instance member through a reference that is null.

Example pattern:

C#
player1.team.name

when:

Plain text
player1.team = null

Diagnosis focuses on finding the first null reference in the chain.

InvalidOperationException

You may encounter an InvalidOperationException when an operation is not valid for the object's current state.

The exact cause depends on the API being used.

Read the exception message and the failing statement rather than assuming one universal fix.

NotSupportedException

A NotSupportedException can indicate that an attempted operation is not supported in the current context.

Again, the exception name narrows the category.

The message and source location provide the next evidence.

Do Not Memorize a Huge Exception List

A stronger debugging habit is:

  1. identify the exception type;
  2. read the message;
  3. inspect the failing statement;
  4. inspect the runtime state;
  5. connect the failure to the requirement.

The exception type is a clue.

It is not the entire diagnosis.

Exception Handling Comes Later

PC1 currently focuses on understanding program behavior and repairing introductory defects.

Detailed exception handling—such as choosing when to throw or catch exceptions—is taught later.

For now, learn to read exceptions as runtime evidence.