find all throws and catches of exceptions that are not explicitly declared

does idea provide an inspection for this?

i want to find exceptions like these:

try {
  int i = 5; System.out.println(i++);
} catch (Exception e)

and declarations like these:

public int foo() throws Exception {
   return 42;
}

4 comments
Comment actions Permalink

Hello,

Second one should be found by RedundantThrowDeclaration.
As far as I know the first one is not yet addressed.

Thank you

0
Comment actions Permalink

Possible alternates:
Catch Exception/RuntimeException will be highlighted by Generic catch inspection
catch not throwed checked exception won't compile
catch not throwed runtime exception  > highlightning is pointless/very questionable

So i don't see a real case for the subject regarding this part.

Redundant throws also could be detected by inspection;

useful tip: you can invoke Ctrl+Shift+F7 on the try/throws keyword to get highlight related invokations.

regards, Alex

0
Comment actions Permalink

my usecase is:
there are ~2500 classes. at some very few points, someone decided to put "throws exception" in the signature. the call hierarchy is now infested with throws exception declarations which stop at random points with "try ... catch exception -> throw new runtimeexception".
we are in the process of eliminating the roots of the exception throws clauses and now need a tool that can point us at the spots where a method declares "throws exception" that could be removed without producing a compile error.
also, we want to find all spots where "exception" is caught and removing the try/catch would not product a compile error.

both cases are subsets of what the genetic catch inspection would find.

0
Comment actions Permalink

you could apply Redunadant Throw clause inspection several times to get desired effect(if classes to invoke the methods declared via implementation classes). but if invocation is done via interface method with declared throws, obviously you can't do anything with it.

0

Please sign in to leave a comment.