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.
}
-
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.
-
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;
}
- 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.
It sounds like you need to edit the code snippet provided by Visual Studio. You can do this by modifying the
try.snippetfile 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:
You just need to update the try/catch block between the
<Code>nodes.