Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add try catch around highlighted code

I'm refactoring some code and there are tons of functions with no try catch statements that are causing problems.

Is there a keyboard shortcut in VS 2010 to allow me to select an entire function or highlighted code and add a try catch end try statement around it...with the highlighted code automatically ending up under try ?

Just looking for a shortcut

like image 336
Khalid Rahaman Avatar asked Mar 29 '12 17:03

Khalid Rahaman


People also ask

How to surround a code with try catch in eclipse?

In Eclipse, just surround the code you want to enclose with the try-catch block and right-click, then select **Surround with > Try Catch **block. Although you can only have one try statement per try-catch block, you can have multiple catch blocks.


2 Answers

I'm not aware of a keyboard short-cut, but there's a right-click available.

  • Highlight the code for your try block.
  • Right click and select
  • "Surround with..." Scroll down the selection until you see the "try" snippet label.
  • There you go!

Hope this helps!

I'll dig around to see if there's a keyboard short cut for this. There probably is -- there's hundreds of them.

UPDATE: Looks like the keyboard shortcut is Ctrl + K, Ctrl + S.

like image 90
David Hoerster Avatar answered Nov 09 '22 04:11

David Hoerster


Download this free addon and then right click and surround with !

(Don't forget to give it 1+ )

https://marketplace.visualstudio.com/items?itemName=yatki.vscode-surround

enter image description here

like image 29
grepit Avatar answered Nov 09 '22 05:11

grepit