You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/10/31 22:06:15 UTC

[GitHub] [netbeans] negora opened a new issue, #4897: Inform about unnecessary exceptions in the "throws" clause of a method

negora opened a new issue, #4897:
URL: https://github.com/apache/netbeans/issues/4897

   ### Description
   
   It would be useful if NetBeans IDE informed about unnecessary checked exceptions in the `throws ` clause of a method. By *unnecessary checked exceptions* I'm referring to checked exceptions that can never be thrown by the body of a method, be it directly (with a `throw` statement) or indirectly (by a call to another method).
   
   
   ### Use case/motivation
   
   Why would this be useful? Because of the following: When we refactor methods, sometimes we leave by mistake exceptions that can't occur anymore. This doesn't cause any error *per se* in the application, but it's confusing when you read the code and also forces the methods up in the call stack to handle or propagate an exception that shouldn't be there.
   
   Someway, the IDE is already aware of which exceptions are thrown in a method's body: if you put the cursor in an exception of the `throws` clause, the IDE highlights which lines may throw it (as @mbien commented on [Java: How to know if a thrown exception is unnecessary?](https://github.com/apache/netbeans/discussions/4086) ).
   
   I'm aware that in the case of a method that overrides an abstract method, it may occur a false positive. Suppose that the abstract method throws an `IOException` but the implementation doesn't throw that exception at all. The IDE might show a warning, even although the abstract method declares such exception (I guess it depends on how much code it analyses). To me, that wouldn't be a big problem: you could just ignore the warning or you could remove the exception from the declaration of the concrete method (the exception would still be there implicitly).
   
   For example, this is what happens when you implement `Appendable.append()`, which declares a `throws IOException` regardless you never throw one.
   
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a pull request?
   
   No
   
   ### Code of Conduct
   
   Yes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists