2

I'm looking for a tools, to check if "try-catch" is used properly in codes.

E.g. I have a method:

/// <exception cref="NotImplementedException">Not implemented</exception>
public void MethodThrowException()
{
  throw new NotImplementedException();
}

I have some calls of this method:

 1 void TestA()
 2 {
 3   MethodThrowException();
 4 }

 5 void TestB()
 6 {
 7   try
 8   {
 9     MethodThrowException();
10   }
11   catch
12   {
13   }
14 }

15 void TestC()
16 {
17   try
18   {
19     MethodThrowException();
20   }
21   catch
22   {
23     throw;
24   }
25 }

26 void Main()
27 {
28   TestA();
29   TestB();
30   TestC();

31   try
32   {
33     TestA();
34     TestB();
35     TestC();
36   }
37   catch
38   {
39   }
40 }

Now I let the tool to inspect for MethodThrowException

I wish to get following result:

File xxx, Method TestA(), Line 3, no try-catch.

File xxx, Method TestB(), Line 9, catch exception.

File xxx, Method TestC(), Line 23, re-throw.

File xxx, Method Main(), Line 28, no try-catch.

File xxx, Method Main(), Line 30, re-throw without try.

File xxx, Method Main(), Line 33, catch exception.

File xxx, Method Main(), Line 35, catch exception.

I also want the tool can generate a report for a project o solution, which looks like:

File xxx, Method "MethodThrowException()", 2 calls is not surrounded with try-catch.

(other methods)

Is there any existing tools or plugins can achieve this?

  • Welcome aboard. Great question! I am just hoping that you will get an answer that also works for other languages :-) – Mawg says reinstate Monica Dec 6 '19 at 8:55
  • 1
    "Is there any existing tools or plugins can achieve this?" - plugins for what? – Mawg says reinstate Monica Dec 6 '19 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.