Link to Us

Debugging & Handling Exceptions in Visual Basic
debugging in vb
Visual Studio detects syntax errors and underlines then in blue
Warnings are underlines in green

To debug you must be in debugging mode
Press F5 or the play button to run your project
visual studio run button
vs tools for debugging
Visual Studio Tools for debugging

Error Window
When you have an error it will show up in the error window
Double-click on the error and it takes you to that part of the code
vs error window
Open the error windows by selecting View Error List or View Other Windows and then errorList
vs error list
Place this on a line of code to pause execution at that point

Immediate Window
Lets you type commands and see potential results

 Your application must be paused to view the value of the variables
set up breakpoints
Set up Breakpoints
Create a breakpoint by clicking in the gray bar to the left of your code.
Click next to the line of code you want to pause at
A red dot appears in the gray bar indicating a breakpoint
vb breakpoint
To remove the breakpoint cimply click it again

When you click play, the program stops at this line

F5 continues execution
breakpoint window
Breakpoint Window
Control + ALT+B opens the breakpoint window
visual studio breakpoints window
Or Debug menu and click Windows and then Breakpoints
from menu windows breakpoints
Use this window to keep track of all your breakpoints
immediate window
Immediate Window
Use the Debug.print command to view values
(?) Question mark is a shortcut for Debug.print

Project must be in a paused state

  • Start as new project
  • Add this code

Dim num1 As Integer = 0

  • Add a button and add this code

num1 += 1

Add two breakpoints next to the code
2 breakpoints

  • Open the immediate window
  • Type ?num1


  • Click on F10
  • Click the button
  • Click F10 and type ?num1
  • Until the value turns to 1

Notice how it is stepping through your code
visual studio exceptions and debugging