• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

What is suppressed exception and how to get those exception in this try with resource program ?

 
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Can anyone please tell me what is suppressed exception, possible furnish a resource and how can I get suppressed exceptions of this program ?
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganish Patil wrote:
Can anyone please tell me what is suppressed exception, possible furnish a resource and how can I get suppressed exceptions of this program ?



Suppressed exceptions are those exceptions thrown by the app but ignored.

If you compile your code with "javac -Xlint:all ..." you may get a whole bunch suggestions/warnings, one of these is suppressed warnings.

http://howtodoinjava.com/2013/03/13/suppressed-exceptions-in-java-7/ gives an overview and some examples about suppressed exceptions.
 
Marshal
Posts: 73745
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go through the Java™ Tutorials, too.
 
Ganish Patil
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, the first one is good one
 
Saloon Keeper
Posts: 13191
286
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganish Patil wrote:



Please don't write code like this. Try-with-resources automatically closes your resources, and handles the exceptions that may occur during closing. Also, if an exception is thrown when inputStream is closed, outputStream will never be closed. The following code is more clear and robust:

 
Ganish Patil
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Stephan do you mean to say that I don't need try, catch and finally block inside try with resources block ?
 
Stephan van Hulst
Saloon Keeper
Posts: 13191
286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not for the purpose of operating with the resources. You may still need nested try statements if you're performing another operation that may throw an exception, and you want to handle the exception and continue running the outer try clause.

However, a nested try statement without any other statements in the same scope is always useless.
 
Stephan van Hulst
Saloon Keeper
Posts: 13191
286
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For instance, let's say I want to read a file that has a number of records. The library that I use to read the records throws an exception if a record is corrupt. When I detect a corrupt record, I would still like to go on and try reading the rest of the records. Here's how I would do it:
 
Ganish Patil
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice explanation Stephen thank you
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic