Chapter 12. Exception Handling: Putting out Fires Gets old

Images

Programmers aren’t meant to be firefighters.

You’ve worked your tail off, wading through technical manuals and a few engaging Head First books, and you’ve reached the pinnacle of your profession. But you’re still getting panicked phone calls in the middle of the night from work because your program crashes, or doesn’t behave like it’s supposed to. Nothing pulls you out of the programming groove like having to fix a strange bug...but with exception handling, you can 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.

Images

But what happens if you give HexDump an invalid filename?

When you modified your HexDump app to use command-line arguments, we asked you to be careful to specify a valid filename. What happens when you give it an invalid filename? Try running your app again from the command line, but this time give it the ...

Get Head First C#, 4th 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.