Finding those pesky bugs using “Break, First Exceptions”.

This is one of those instances when punctuation and grammar counts ie “I helped my uncle Jack, off a horse” vs “I helped my uncle jack off a horse” ….

Break, first exceptions is a method of debugging where you set Visual Studios up, to create a break point at the first instance of an exception. This is particularly useful when exception handling hasn’t been properly implemented or an empty Try – Catch block has been created and the exception is silently getting handled and not getting reported to the user ( or the developer ).

Here are the steps in order to setup up Break, first exceptions.

  1. In visual studios (2010 in this case) click on debug -> Exceptions or press the shortcut of ctrl+alt+e
  2. In the Exception dialog box, select Thrown for the category of “Common Language Runtime Exceptions”

That’s all there is too it. Have fun killing those bugs.

Increase Productivity by Organizing Your Code with #Region Tags

As developers we are often pushed into over-drive with strict deadlines, and tight sprints. Often we forget about code organization. One way to help maintainability and to keep your code organized is to use #region tags. I often found myself repeatedly typing   #regions Fields #endregion #region Properties ….

One easy way to automate this process is to create a code snippet that will fill in all the #regions for you. Code snippets are essentially just an XML file with a .snippet extension. Below is a sample of my code snippet.

Visual Studio Code Snippet

In order to import this code snippet into visual studios

  1. Create a new XML file using the sample code above. For the full xml schema go to http://msdn.microsoft.com/en-us/library/ms171418.aspx
  2.  Now Save the file as “EmptyRegions.snippet”
  3. Open up the Code Snippet Manager by pressing Ctrl+K, Ctrl+B. or by going to Tools then clicking on Code Snippet Manager
  4. Click on Import and browse to the location where you saved the file “EmptyRegions.snippet”
  5.  Now choose a location to save your Code Snippet, for this example I selected “My Code Snippets” Click Finished
  6. You should now see the “EmptyRegions” snippet in your “My Code Snippet” Click OK when finished
    Code Snippet Imported
    Now in the editor just start typing emptyRegions once you see intellisense pop up with the correct short cut, hit tab twice. You should now see the code inserted into the editor
    intellisense

That’s all, now you have a starting point to help keep your code organized without having to repeat yourself over and over and over again.