Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Throwable's getSuppressed() method ?

 
Ranch Hand
Posts: 115
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly does this method return ? It actually returns a Throwable[].


The code above prints: e.getSuppressed().length = 0 , but should getSuppressed not contain ArrayIndexOutOfBoundsException and print 1 ?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppressed exceptions are only added automatically in a try with resources statement.
If you want suppressed resources to be added in any other situation you need to do it yourself.
 
Marshal
Posts: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a short section about it in the Java Tutorials. I presume you have read about the getSuppressed method?
 
Myke Enriq
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:Suppressed exceptions are only added automatically in a try with resources statement.
If you want suppressed resources to be added in any other situation you need to do it yourself.



Thank you all for your replies. I have read the tutorial http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html , yet it is a bit unclear to me how do suppressed exceptions get automatically added.

Could someone please provide an example of an auto generated/added suppressed exception ?
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic