Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:55:50+00:00 2026-05-30T07:55:50+00:00

whenever we need to exception handling, we will surround with try/catch block, but when

  • 0

whenever we need to exception handling, we will surround with try/catch block, but when we surround try/catch block, Visual studio will give like this.

try
{
}
Catch (Exception e)
{
  // here we need to write code for logging every time manually. 
}
  1. can we automate the process, of catch block with our own exeception logging code which will be the same all time. what i mean, whenever i surround method, can include our own logging codes into exception block automatically ? is there any tool or work around.

  2. the main reason asking for these, many jr.developer will not handle exception or logging, though we review code, what i tought will make automation whenever we surround try/catch block in our method which need to be logging, in catch block it will include all our logging code.

may be like this

Catch(Exception e ) // i am telling it for a function, not as global catch handler. 
{                   // logging at method/function level. for method which we need to log
  ourLogging obj = new Ourlogging(); // these two line should added automaticaly, 
  obj.Publish(e);                   //as when user surrounded with try/catch block ? 
  obj = null; 
}
  1. if is there any visual studio addon or some work around, or if any body have some tool or script to achive this task it would be helpful, to many fellow developer.

i hope every one understood my question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:55:51+00:00Added an answer on May 30, 2026 at 7:55 am

    It sounds like you need to edit the code snippet provided by Visual Studio. You can do this by modifying the try.snippet file typically located here:

    C:\Program Files\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#

    The default contents of this file are as follows:

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>try</Title>
                <Shortcut>try</Shortcut>
                <Description>Code snippet for try catch</Description>
                <Author>Microsoft Corporation</Author>
                <SnippetTypes>
                    <SnippetType>Expansion</SnippetType>
                    <SnippetType>SurroundsWith</SnippetType>
                </SnippetTypes>
            </Header>
            <Snippet>
                <Declarations>
                    <Literal>
                        <ID>expression</ID>
                        <ToolTip>Exception type</ToolTip>
                        <Function>SimpleTypeName(global::System.Exception)</Function>
                    </Literal>
                </Declarations>
                <Code Language="csharp"><![CDATA[try 
        {           
            $selected$
        }
    
        catch ($expression$)
        {
            $end$
            throw;
        }]]>
                </Code>
            </Snippet>
        </CodeSnippet>
    </CodeSnippets>
    

    You just need to update the try/catch block between the <Code> nodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to delete a Course object, I get this exception: Referential integrity
I usually use C++ stdlib map whenever I need to store some data associated
In C#, Whenever i need to get file path more dyanmically, i do something
I need to notify my application in some way whenever any file in the
I need to write a trigger that rounds a value whenever it is inserted/updated
I have a need to create a HttpSession (via cookie) whenever a client invokes
Whenever I want to modify a winform from another thread, I need to use
For my web application I need to close the child window whenever the parent
Im developing a touchscreen app and I need to hide the cursor whenever it
Whenever I try to add a new project to my SourceSafe repository it creates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.