add try catch around highlighted code

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


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.