How to Debug VB .NET Code - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

How to Debug VB .NET Code

Description:

Also known as a syntax error. These occur when the environment you're ... After all, you're the programmer, and you should write code to trap runtime errors. ... – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 13
Provided by: reha6
Category:
Tags: net | bottomleft | code | debug | trap

less

Transcript and Presenter's Notes

Title: How to Debug VB .NET Code


1
How to Debug VB .NET Code
2
Types of Error
  • Programming errors are generally broken down into
    three types
  • Design-time,
  • Runtime,
  • and Logic errors.

3
Design-time error
  • Also known as a syntax error. These occur when
    the environment you're programming in doesn't
    understand your code.
  • These are easy to track down in VB.NET, because
    you get a blue wiggly line pointing them out.
  • If you try to run the program, youll get a
    dialogue box popping up telling you that there
    were Build errors.

4
Runtime errors
  • A lot harder to track down. As their name
    suggests, these errors occur when the program is
    running. They happen when your program tries to
    do something it shouldnt be doing. An example is
    trying to divide by zero.
  • Runtime errors usually cause your program to
    crash. If and when that happens, you get the
    blame. After all, youre the programmer, and you
    should write code to trap runtime errors.

5
Logic errors
  • Also occur when the program is running. They
    happen when your code doesnt quite behave the
    way you thought it would.
  • A classic example is creating an infinite loop of
    the type Do While x is greater than 10. If x is
    always going to be greater than 10, then the loop
    has no way to exit, and just keeps going round
    and round.
  • Logic errors tend not to crash your program. But
    they will ensure that it doesnt work properly.

6
Logic errors
  • There will be no wiggly lines and therefore no
    Build errors.
  • Also, no runtime exception will crash the
    program.
  • So how to find out where is the logical error?
  • Here comes the debugger job.

7
Breakpoints
  • Another weapon in your debugging armory is the
    Breakpoint.
  • A breakpoint is like a note to VB.NET to stop
    your program at a particular place. You add one
    to your code by clicking in the margins.
  • A brown circled then appears, indicating where
    the code will break.
  • The following two images show how to add one

8
Breakpoints
  • Run your program again. You are immediately
    returned to the coding window.
  • The place where you put the breakpoint will now
    have a yellow arrow on top of the brown circle.
  • The brown highlighted line will now be yellow

9
Breakpoints
  • The yellow highlight indicates where in your code
    VB.NET is.
  • To continue checking
  • your code, press F10 on your keyboard (you
    can also press F11, but this will jump into any
    Subs or Functions youve set up.)
  • The next line in your code will be highlighted

10
Breakpoints
  • The yellow arrow, and the yellow highlight, jump
    down one line. Press the F10 key again.
  • Then hold you mouse of the letter variable.
  • The value this variable currently holds will be
    displayed

11
Breakpoints
  • You can continue pressing the F10 key until
    youve spotted the error. Or you can use
  • another debugging tool the Locals window.
  • While your program is still in Debug mode (the
    yellow line will still be there, if it is), click
    Debug gt Windows gt Locals from the menu bar.
  • You should see the following in the bottom left
    of your screen

Locals means Local variables. That is,
variables declared in this section of the code.
12
Commenting your code
  • In some cases you need to comment out a whole
    block of code.
  • To do so, highlight it first. Then click the
    comment icon on the toolbar
  • The icon next to it removes the comments from
    highlighted code.
Write a Comment
User Comments (0)
About PowerShow.com