Howto activate eclipse java warning "unnecessary declaration of thrown exception" without getting false positives? -


i hate functions declare throw exceptions not thrown functions in case. happens in refactorings if throw statements removed in function body without removing throws definitions.

thats why activated setting java -> compiler -> errors/warnings -> unnecessary code -> unnecessary declaration of thrown exception.

enter image description here

this leads false positive warnings if exceptions defined in interfaces or super methods. if implementation of interface not throw 1 exception type, implementation b does, eclipse warns unnecessary declaration in implemantation a. thats equally super , overriden methods. thats why activate suboption "ignore in overriding , implementing methods".

perfeclty fine till here. have oposite case. overridden method throws exception type, not used in super method. see minimal example:

class vehicle {     protected int getstatus() throws generalexception, statusexception {         throw new generalexception("one exception type in super type only");     } }  class car extends vehicle {     @override     protected int getstatus() throws generalexception, statusexception {         throw new statusexception("special case, gets special handling");     } } 

now statusexception in vehicle warned in eclipse.

enter image description here

of course 1 argue bad design etc., pragmatic point of view happen again , 1 can accept not change architecture, add new exception type super type. but howto rid of false positive warning in case? of course 1 use suboption javadoc, ignore real positive hits. option add suppresswarning annotation "unused", other users unneeded warnings suppression.

personally i'd activate second option under warning setting: "ignore exceptions documented..." , document those:

/**  * @throws generalexception when general stuff goes wrong  * @throws statusexception when status stuff goes wrong  */ protected int getstatus() throws generalexception, statusexception {     throw new generalexception("one exception type in super type only"); } 

maybe include more useful explanation, it'll boild down this.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -