File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes SuppressedException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic


meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Have you any idea how to generate an exception in above resources statement ?


My one regret in life is that I am not someone else.
- Woody Allen
Waldemar Macijewski
Ranch Hand

Joined: Jun 22, 2012
Posts: 32

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.

for example:

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

I want to generate an exception in resources statement to check for suppressed exception.
Tony Docherty

Joined: Aug 07, 2007
Posts: 2837
Please don't start new threads to ask questions related to the same problem. All further discussion should be directed to

I'm locking this thread.
I agree. Here's the link:
subject: SuppressedException
It's not a secret anymore!