finding and debugging errors

24
Finding and Debugging Errors

Upload: deana

Post on 20-Feb-2016

89 views

Category:

Documents


0 download

DESCRIPTION

Finding and Debugging Errors. Categories of Errors. Syntax errors are detected at compile time Use the Error List window to find these errors The debugging tools cannot help with syntax errors Runtime errors occur as an application executes - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Finding and Debugging Errors

Finding and Debugging Errors

Page 2: Finding and Debugging Errors

Slide 2

Categories of Errors Syntax errors are detected at compile

time Use the Error List window to find these

errors The debugging tools cannot help with

syntax errors Runtime errors occur as an

application executes Logic errors cause an application to

produce unexpected results but do not cause exceptions

Page 3: Finding and Debugging Errors

Slide 3

Types of Runtime Errors File processing errors Arithmetic errors Null reference errors

And many more

Page 4: Finding and Debugging Errors

Slide 4

File Processing Errors Sequential files with extra trailing

carriage returns will generate errors Sequential files with extra or missing

fields will also cause errors Omitting the carriage return on the last

record may cause the last record to be ignored

Page 5: Finding and Debugging Errors

Slide 5

Arithmetic Errors (1) Numeric overflow results in the following

exception: Correct by performing double precision

arithmetic instead of integer arithmetic

Page 6: Finding and Debugging Errors

Slide 6

Arithmetic Errors (2) Trying to convert an invalid value to a

number will result in a System.FormatException

Call TryParse() to test before conversion

Page 7: Finding and Debugging Errors

Slide 7

Arithmetic Errors (3) Integer division by zero throws a System.DivideByZeroException:

Fix by testing the dividend value

Page 8: Finding and Debugging Errors

Slide 8

Arithmetic Errors (4) Division by zero is handled differently

for floating point numbers and floating point division

Division by zero results in the value Infinity

Test usingDouble.IsInfinity(Value)

Page 9: Finding and Debugging Errors

Slide 9

Null Reference Errors (Introduction) Pure and simple, you reference an

object with first creating an instance of that object

The following exception is thrown

Page 10: Finding and Debugging Errors

Slide 10

Interrogating the Value of a Variable or Property Do while the application is in break

mode In the Code Editor, highlight the

variable, object, or property Expand or collapse complex objects as

necessary

Page 11: Finding and Debugging Errors

Slide 11

Interrogating the Value of a Variable or Property (Example)

Page 12: Finding and Debugging Errors

Slide 12

Setting Breakpoints (1) Use to temporarily suspend execution

while a program runs Multiple breakpoints may be set Breakpoints may be enabled or disabled It’s possible to clear all breakpoints Breakpoints are persistent between

invocations of Visual Studio

Page 13: Finding and Debugging Errors

Slide 13

Setting Breakpoints (2) Set simple breakpoints on a line by

clicking in the left margin in the Code Editor A maroon circle appears in the left margin

Breakpoints may be set only on executable statements because declaration statements don’t execute!

Page 14: Finding and Debugging Errors

Slide 14

Setting Breakpoints (3) Breakpoints appear in the Breakpoints

window

Page 15: Finding and Debugging Errors

Slide 15

Setting Conditional Breakpoints Break when a condition becomes true or

a value changes Use for problems having long iteration

counts

Page 16: Finding and Debugging Errors

Slide 16

Setting Hit Count Breakpoints Break on an iteration count

Hit count breakpoints are configurable

Break after 999 iterations

Page 17: Finding and Debugging Errors

Slide 17

Setting Conditional Breakpoints Conditional breakpoints are hit when

The value of a Boolean condition is True The value of a condition has changed

Page 18: Finding and Debugging Errors

Slide 18

Setting Conditional Breakpoints (Illustration) Set a conditional breakpoint

Page 19: Finding and Debugging Errors

Slide 19

Setting WatchPoints There are multiple Watch windows Each works the same way Just create an expression to be watched Use Watchpoints instead of repeatedly typing

the same expression in the Immediate window Beware of setting too many Watchpoints –

Execution will become quite slow

Page 20: Finding and Debugging Errors

Slide 20

Setting WatchPoints (Illustration) Watch the variable “f”

Page 21: Finding and Debugging Errors

Slide 21

Other Debugging Windows (1) The Autos window shows variables used

in the current and previous statement

Page 22: Finding and Debugging Errors

Slide 22

Other Debugging Windows (2) The Locals window displays variables

local to the current context

Page 23: Finding and Debugging Errors

Slide 23

Other Debugging Windows (3) Call stack shows the procedures and the

order in which the procedures were called

Page 24: Finding and Debugging Errors

Slide 24

Exceptions Use to change

the handling of exceptions when they occur