Visual Studio Code Snippet Tutorial

If you code in Visual Studio, there are things that you do over and over. I try as much as possible to reduce the repletion because it just goes faster, and I'm impatient like that.

That's why we started this site and www.TelerikDeveloper.com, to blog all the cool code samples so that we only type them once.

To that end, I type this all the time:

Sub TestSub()
       Try
 
       Catch ex As Exception
           ErrorHandler.globalErrorHandler(ex, True)
       End Try
 
 
   End Sub

I created a Code Snippet to automate the typing. If you've never seen how a Code Snippet works, you really should read this.

 Go to Tools > Code Snippet Manager

Change the language to Visual Basic

Expand the node that starts with Code Patterns

Expand Error Handling (Exceptions)

Click once on Try...Catch...End Try Statement

Copy the Location into Windows Explorer

Edit the 'ShortCut' node like this

<Shortcut>Tryy</Shortcut>

Edit the 'Code' node to be as below

<Code Language="VB" Kind="method body"><![CDATA[Try
 
Catch ex As exception
  errorhandler.globalerrorhandler(ex,true)
End Try]]></Code>

Save, and you're done.

You'll obviously have your own error handling code.

Save and Close

In Visual Studio, type TRYY and then hit the tab.

Nice, right?


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences