Have you any idea how to generate an exception in above resources statement ?
Joined: Jun 22, 2012
You do not generate any exceptions, by using try and catch keywords you monitor piece of code which may create an exception and by using catch, you can "catch" this exception and handle it in some appropriate way. If you are referring to try with resources statement, then in try clause you declare and initialize objects whose resources are automatically managed. For example, if you create an instance of FileOutputStream, then any resources which are associated with this object (such as files in this case, but there also may be other resources such as network sockets, etc) are automatically closed. There is no need to call close() method in finally block.