Chapter 9

Some Exceptional Exceptions

IN THIS CHAPTER

check Handling errors via return codes

check Using the exception mechanism instead of return codes

check Plotting your exception-handling strategy

It’s difficult to accept, but occasionally a method doesn’t do what it’s supposed to do, which results in an error. (If you need to learn about methods, read the third chapter of Book 2). Users are notoriously unreliable as well. No sooner do you ask for an int than a user inputs a double, which also results in an error. Sometimes the method goes merrily along, blissfully ignorant that it is spewing out garbage. However, good programmers write their methods to anticipate problems and report them as they occur.

remember This chapter discusses runtime errors, not compile-time errors, which C# spits out when you try to build your program. Runtime errors occur when the program is running, not at compile time.

The C# exception mechanism is a means for reporting these errors in a way that the calling method can best understand and use to handle the problem. This mechanism has a lot of advantages over the ways that ...

Get C# 7.0 All-in-One For Dummies 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.