Debugging and Error Handling
Chapter 5
Ebook: Beginning Visual C# 2010, chapter 7
Reference: CSharp How to Program, part D
Contents
Introduction
Debugging
Error handling
Slide 2
Introduction
Errors in program: a program can have three types of
errors:
compile-time errors: The compiler will find syntax errors
and other basic problems
run-time errors: A problem can occur during program
execution, such as trying to divide by zero, which causes a
program to terminate abnormally
logical errors: A program may run, but produce incorrect
results, perhaps using an incorrect formula
1-3
Debugging
Debugging is the process of finding and correcting
logic errors in applications
applications are executed in two ways: with debugging
enabled (F5) or without debugging enabled (Ctrl+F5)
Techniques
debugging in nonbreak mode
outputting debugging information: Console.WriteLine(),
Debug.WriteLine()
debugging in break mode
using Breakpoints
Some windows in Debug\Windows: Autos, Locals,
Watch
demo… Slide 4
Error handling
An exception is an indication of a problem that occurs
during a program's execution
format error,
arithmetic overflow,
out-of range array subscripts,
division by zero,
invalid method parameters
running out of available memory,
Your program should be able to handle these
exceptional situations. This is called exception
handling
Slide 5