Auto-generate a try catch block in visual studio 2010

為{幸葍}努か 提交于 2019-11-30 06:01:21
sshow

Using the mouse

  1. Mark your code

  2. Right-click

  3. Select Surround with...

  4. Double-click try

Using the keyboard #1

  1. Mark your code using Shift, Ctrl + A, or whatever works for you

  2. Press Menu key / Application key (alternatively Shift + F10)

  3. Type S

  4. Type T

  5. Press Enter or Tab

Using the keyboard #2 (as perlox and Fredrik Norlin points out)

  1. Mark your code using Shift, Ctrl + A, or whatever works for you

  2. Press Ctrl + K, followed by CTRL + S

  3. Type T

  4. Press Enter or Tab

Peter Perháč

type try then hit Tab,Tab

2 x Tab activates a code snippet.

type tryf , Tab,Tab to activate the try..finally block instead

Sam

I was going to comment on sshow's post (since this doesn't require a whole "answer"), but I can't since I don't have enough points...if you don't want to remove your fingers from the keyboard, you can hit Ctrl + K, Ctrl + S, then T, then Enter. That's basically what he said, but without using the mouse.

http://msdn.microsoft.com/en-us/library/6hf704tz%28VS.80%29.aspx

Have you tried using snippets?

I use CodeRush from DevExpress. I can use the key strokes "TC" to generate. It works with C# too.

    Try

                Catch ex As Exception
                    dmPrgm_Err(Err, ex)
                End Try

I then can use TSC for a Try SQL Catch with custom message boxes.

            Try

                Catch ex As SqlException
                    dmSQLErr(ex)
                Catch ex As Exception
                    dmPrgm_Err(Err, ex)
                End Try
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!