The AutoCloseable has a method 'void close throws Exception'. Some suggest to extend this interface and override the close method and remove the Exception. See for instance the below link.
But when i forget to put the statement in a try-with-resources statement is the close method than not called?
- In the try-with-resources the close is called
- In the stream api the close is called
- Automatically by java when for instance leaving the method in which the resource is created???
Additional information I've searched on the internet and looked at the documentation. Both suggested to remove the throws Exception statement. But my reaction to this suggestion is that when in the future someone in our project implements the new interface (without exception) and forgets to put them in the try-with-resource that we have a resource leak. For our project it's not a huge issue because we're using SonarQube which will mention the resource leak
Example location: