Home Contents Search GhostDepot Vb.Net Depot

 Visual Studio Tips VB Printing Samples


VB Debugging Runtime Errors



Visual Studio Debugging Tips


1. Use Option Strict On to show Errors while editing

Put the line:

   Option Strict On

as the first line of code in your form as shown in the example.

Then Visual Studio will show design time errors to you while editing by underlining or highlighting the errors several ways. The project will not run until the errors are corrected. Plus, you can sometimes click the error highlights and get the correct syntax or other suggestions.


Adding Option Strict to a Form.


You can also set Option Strict for the Project in the Visual Studio menu item Project - Properties - Debug tab.




2. Set the Debugger to Break on Errors

Make sure your project is set to break on errors in debug using the menu item Debug - Window - Exceptions (or just Debug - Exceptions depending on VS version) and make sure all items for Common Language Runtime errors is checked. Otherwise you could be getting an error but Visual Studio is not showing it.

Select the menu item Debug - Windows - Exception Settings:


Check Common Language Runtime Exceptions (all items):




3. Set execution Break Point and Examine the Values

A break point causes code execution to stop on a selected line when you are running in the design environment.

You can make a break point several ways. One way is put a line with the word Stop in your code.

Another way to set a break point is to use the mouse to click the left border of the Visual Studio code window. That creates a red line at the break and then when you run the code it stops execution on that line (when paused the break is shown with a yellow highlight):



When you stop the code execution at a break point, examine the values with Intellisense by hovering the mouse over the variables.


Single Step execution

You can run your code one line at a time with the Single Step feature on the Debug Toolbar.

You can start your application at the first line or pause execution and then single step execution of each line of code. As you step you can look at the values of variables and follow where your code is going.





The images on this page are from Visual Studio 2015.






Copyright 2000 - 2019 Sandia Software