Stage 1 · Lesson 8 of 9
Exceptions and debugging
C# signals errors with . The names the exception, such as FormatException or FileNotFoundException, gives the message and points at the line. Read it before changing anything.
Handle expected failures with try, catch and finally, and catch the narrowest type you can. An empty catch (Exception) block hides real bugs. A using declaration, using var reader = new StreamReader(path);, disposes of (closes) the file automatically, even when an exception is thrown.
Throw your own exception for bad input, such as throw new ArgumentException("amount must be positive"). C# has no checked exceptions, so the compiler will not remind you what might fail. Check the documentation for what a method can throw. For wrong output, step through with the debugger.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- GuideFreeLearn C#
Microsoft · Beginner
Official C# fundamentals tutorials that you run locally with the .NET SDK
- PlatformFreefreeCodeCamp
freeCodeCamp · Beginner
Free Foundational C# certification, built with Microsoft, with a graded exam at the end