Try/Catch.../End Try Template

Would like a way to alter this template

Page 1 of 1

6 Replies - 2802 Views - Last Post: 07 July 2009 - 10:53 AM Rate Topic: -----

#1 STDad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-December 08

Try/Catch.../End Try Template

Post icon  Posted 24 June 2009 - 07:23 AM

As a convenience, when I type "Try" into a new routine, Visual Basic changes it to:
Try

Catch ex As Exception

End Try


Is there a way to alter this template so that it comes up something like:

Try

Catch ex As Exception
	 <Our Standard Error Handling Code>
End Try


Our standard error handling code doesn't change. (Which is why we came up with it.) For some reason, if a way exists, I'm having trouble finding it because I'm not using the correct search terms; Try, Catch, etc. bring up routines that actually have this code and "template" doesn't narrow it down enough either.

This would be a real time saver!

Thanks!
STDad

Is This A Good Question/Topic? 0
  • +

#3 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Try/Catch.../End Try Template

Posted 24 June 2009 - 07:59 AM

Think a making that code section a snippet.
Did you know its possible to put sections of code into the toolbox.

Pin the toolbox open.
Highlight a section of code
Drag & drop it into the toolbox.

When you need to reuse it drag & drop from toolbox into the code editor.
Was This Post Helpful? 1
  • +
  • -

#4 eworm   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 64
  • Joined: 17-March 09

Re: Try/Catch.../End Try Template

Posted 24 June 2009 - 08:52 AM

If you go to Tools -> Code Snippets Manager: Then browse to the Code Patterns folder / Error Handling (Exceptions) / Try...Catch...End Try Statement

And it'll show the path of the snippet above in the text field. Copy and paste that path and then open up that snippet in VB.NET.

Now I'm not sure if you've already done this... but it might be a place to play around with. I tried it and I couldn't get it to change when I modified the snippet in anyway. But maybe it'll point you in the right direction.
Was This Post Helpful? 1
  • +
  • -

#5 STDad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-December 08

Re: Try/Catch.../End Try Template

Posted 26 June 2009 - 01:43 PM

Thank you, both.
I will try these this weekend and report back.
-STDad
Was This Post Helpful? 0
  • +
  • -

#6 STDad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-December 08

Re: Try/Catch.../End Try Template

Posted 07 July 2009 - 10:07 AM

View PostAdamSpeight2008, on 24 Jun, 2009 - 06:59 AM, said:

Think a making that code section a snippet.
Did you know its possible to put sections of code into the toolbox.

Pin the toolbox open.
Highlight a section of code
Drag & drop it into the toolbox.

When you need to reuse it drag & drop from toolbox into the code editor.


Adam,

This worked brilliantly! I love the idea and also the way it expands as a tooltip so you can see the code while you mouse-hover.

-Scott
Was This Post Helpful? 0
  • +
  • -

#7 STDad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-December 08

Re: Try/Catch.../End Try Template

Posted 07 July 2009 - 10:36 AM

View Posteworm, on 24 Jun, 2009 - 07:52 AM, said:

If you go to Tools -> Code Snippets Manager: Then browse to the Code Patterns folder / Error Handling (Exceptions) / Try...Catch...End Try Statement

And it'll show the path of the snippet above in the text field. Copy and paste that path and then open up that snippet in VB.NET.

Now I'm not sure if you've already done this... but it might be a place to play around with. I tried it and I couldn't get it to change when I modified the snippet in anyway. But maybe it'll point you in the right direction.



eworm,

The problem with this one was that "Code Snippets Manager" was NOT on my Tools menu. Since I did not find it there I, well, sort of assumed you were wrong or had a different version. No, Microsoft's site said the same thing, so I:
-Right-Clicked on "Tools"
-Chose "Customize"
-Clicked on the "Commands" tab
-Scrolled down to and clicked on "Tools"
-Clicked on "Code Snippets Manager"
-Dragged it to the "Tools" menu
-Waited for the "Tools" menu to expand
-Dropped it on the end of the menu
It's now there. From there on, I could follow your instructions. (Since you gave advice, you probably know exactly how to do this, but I like to leave these types of instructions for anyone who may not know.)

This did not add my code to the standard insert it does for typing "Try" and pressing enter... I think adding the code to my toolbox will work better...
"HOWEVER" I now have WHOLE NEW code library to explore...Way cool!!

This is an entirely new resource available on my machine and this will come of use further down the line.

Thank you SO MUCH!

-STDad
Was This Post Helpful? 0
  • +
  • -

#8 eworm   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 64
  • Joined: 17-March 09

Re: Try/Catch.../End Try Template

Posted 07 July 2009 - 10:53 AM

View PostSTDad, on 7 Jul, 2009 - 09:36 AM, said:

This did not add my code to the standard insert it does for typing "Try" and pressing enter... I think adding the code to my toolbox will work better...
"HOWEVER" I now have WHOLE NEW code library to explore...Way cool!!

This is an entirely new resource available on my machine and this will come of use further down the line.

Thank you SO MUCH!

-STDad


Sounds good! Glad to hear it!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1