Get 20M+ Full-Text Papers For Less Than $1.50/day. Start a 14-Day Trial for You or Your Team.

Learn More →

A Programmer’s Introduction to C# 2.0Exception Handling

A Programmer’s Introduction to C# 2.0: Exception Handling CHAPTER 4 ■ ■ ■ In many programming books, exception handling warrants a chapter somewhat late in the book. In this book, however, it’s near the front for a couple of reasons. The first reason is that exception handling is deeply ingrained in the .NET runtime and is therefore common in C# code. C++ code can be written without using exception handling, but that’s not an option in C#. The second reason is that it allows the code examples to be better. If exception handling is late in the book, early code samples can’t use it, and that means the examples can’t be written using good programming practices. Unfortunately, this means classes must be used without really introducing them. Read the following section for flavor; we’ll cover the classes in detail in the next chapter. What’s Wrong with Return Codes? Most programmers have probably written code that looks like this: bool success = CallFunction(); if (!success) // process the error This works okay, but every return value has to be checked for an error. If the previous code was written as CallFunction(); any error return would be thrown away. That’s where bugs come from. Many different models exist for http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png

A Programmer’s Introduction to C# 2.0Exception Handling

Editors: Gunnerson, Eric; Wienholt, Nick
Springer Journals — Jan 1, 2005

Loading next page...
 
/lp/springer-journals/a-programmer-s-introduction-to-c-2-0-exception-handling-8YcQMylcJX
Publisher
Apress
Copyright
© Apress 2005
ISBN
978-1-59059-501-5
Pages
21 –30
DOI
10.1007/978-1-4302-0035-2_4
Publisher site
See Chapter on Publisher Site

Abstract

CHAPTER 4 ■ ■ ■ In many programming books, exception handling warrants a chapter somewhat late in the book. In this book, however, it’s near the front for a couple of reasons. The first reason is that exception handling is deeply ingrained in the .NET runtime and is therefore common in C# code. C++ code can be written without using exception handling, but that’s not an option in C#. The second reason is that it allows the code examples to be better. If exception handling is late in the book, early code samples can’t use it, and that means the examples can’t be written using good programming practices. Unfortunately, this means classes must be used without really introducing them. Read the following section for flavor; we’ll cover the classes in detail in the next chapter. What’s Wrong with Return Codes? Most programmers have probably written code that looks like this: bool success = CallFunction(); if (!success) // process the error This works okay, but every return value has to be checked for an error. If the previous code was written as CallFunction(); any error return would be thrown away. That’s where bugs come from. Many different models exist for

Published: Jan 1, 2005

There are no references for this article.