Chapter 6: Managing Errors and Exceptions


Chapter 6

Managing Errors and Exceptions

After completing this chapter, you will be able to:

  • Handle exceptions by using the try, catch, and finally statements.

  • Control integer overflow by using the checked and unchecked keywords.

  • Raise exceptions from your own methods by using the throw keyword.

  • Ensure that code always runs, even after an exception has occurred, by using a finally block.

You have now seen the core C# statements you need to know to read and write methods; declare variables; use operators to create values; write if and switch statements to selectively run code; and write while, for, and do statements to repeatedly run code. However, the previous chapters haven't considered the possibility (or probability) that things can go wrong. It is very difficult to ensure that a piece of code always works as expected. Failures can occur for a large number of reasons, many of which are beyond your control as a programmer. Any applications that you write must be capable of detecting failures and handling them in a graceful manner. In this final chapter of Part I, “Introducing Microsoft Visual C# and Microsoft Visual Studio 2005,” you'll learn how C# throws exceptions to signal that an error has occurred, and how to use the try, catch, and finally statements to catch and handle the errors that these exceptions represent. By the end of this chapter, you'll have a solid foundation in C#, which you will build on in Part II, “Understanding the C# Language.”




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net