Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Three species of failure

โญ beginnerโณ 13 min read๐Ÿ“ Lesson 66 of 85

Compile errors are the compiler protecting you; runtime errors crash; logic bugs pass silently. Different tools for each.

Compile-time: the friendly ones

int x = "hello";        // CS0029: cannot convert
Missing.Method();       // CS0103: does not exist

The compiler refuses to build wrong code and names the file, line, and reason. Fix immediately, before running anything โ€” these are the cheapest failures you will ever see.

Runtime: exceptions

var list = new List<int>();
int first = list[0];    // ArgumentOutOfRangeException: index -1? no: 0, Count 0

The program compiles but hits an impossible state. The stack trace is the treasure: read it bottom-up โ€” the top frame names the throwing line, the frames below name how you got there.

Logic bugs: the dangerous ones

// compiles, runs, and confidently returns the WRONG answer
static double Average(List<int> xs) => xs.Sum() / xs.Count;   // int division!

No exception, no crash โ€” just Average(new[] {3, 4}) == 3. Only tests (or a suspicious user) find these. That's why this module is really about building the habit: assert what you believe.