Chapter 11

Exception Handling and Debugging

What you will learn in this chapter:

  • The differences among bugs, errors, and exceptions
  • Syntax, semantic, and logic bugs
  • Exception handling
  • Throwing exceptions
  • Using the debugger
  • Debugging windows
  • Bug detection, isolation, and correction code downloads for this chapter

You can find the code downloads for this chapter at on the Download Code tab. The code in the Chapter11 folder is individually named according to the names throughout the chapter.

It would be wonderful if this chapter didn't need to be written. However, the truth is that problems do arise when programs are developed and run.

Most experienced programmers agree that approximately 20 percent of program development time consists of writing program code. The remaining 80 percent is used for testing, debugging, and maintenance of that code. Clearly, anything you can do to reduce that 80 percent figure can help keep you on time and on budget.


It's common for programmers to lump bugs, program errors, and program exceptions into a single concept. Technically, each of these types of errors is different. Now consider each in a little more detail.


A bug is a specific type of error caused by the programmer. Bugs typically fall into one of three general categories:

  • Syntax errors
  • Semantic errors
  • Logic errors

Syntax Errors

A syntax error occurs when a statement does not comply with the rules of the language. ...

Get Beginning Object-Oriented Programming with C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.