Chapter 12. Exception Handling Putting out fires gets old

When you have to deal with error after error, it’s called “putting out fires.”

Imagine: it’s a few years from now. You spent all that time working on your C# skills and continuing to learn and improve, and now you’re one of the most senior developers at a big tech company. Now you’re getting panicked phone calls in the middle of the night from your support team because your app crashes, or doesn’t behave like it’s supposed to. You want to spend your time writing code, not putting out fires! Because nothing pulls you out of the programming groove like having to fix a strange bug you don’t recognize. Luckily, C# has exception handling, which lets you write code to deal with problems that come up. Better yet, you can even plan for those problems, and keep things running when they happen.

Your hex dumper reads a filename from the command line

At the end of Chapter 10, you built a hex dumper that uses command-line arguments to dump any file. You used the project properties in the IDE to set the arguments for the debugger, and you saw how to call it from a Windows command prompt or macOS Terminal window.

But what happens if you give HexDump an invalid filename?

When you modified your HexDump app to use command-line arguments, ...

Get Head First C#, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.