Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

SuppressedException

 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator


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

Thanks
 
Waldemar Macijewski
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi

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
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
I want to generate an exception in resources statement to check for suppressed exception.
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't start new threads to ask questions related to the same problem. All further discussion should be directed to http://www.coderanch.com/t/601799/java/java/Throwable-getSupprssed

I'm locking this thread.
 
    Bookmark Topic Watch Topic
  • New Topic