• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • paul wheaton
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • Himai Minh
Bartenders:

Sybex 816. Chapter 5 possible error

 
Ranch Hand
Posts: 53
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Jeanne and Scott. I believe that there is a potential error in Chapter 5 summary and Exam Essentials.

A suppressed exception occurs when more than one exception is thrown, often as part of a finally block or try‐with‐resources close() operation. The first exception to be encountered will be the primary exception, with the additional exceptions being suppressed



A try‐with‐resources statement, as well as a try statement with a finally block, may generate multiple exceptions. The first becomes the primary exception, and the rest are suppressed exceptions.



Maybe, I am wrong, but as I was thinking the only exception thrown in implicit finally of try with resources, in close method will become suppressed. Exception from regular finally will become primary and original exception will be lost.
 
Marshal
Posts: 77577
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java® Language Specification (=JLS) only mentions suppressed exceptions in the context of try with resources. The Throwable#addSuppressed() method was introduced in Java7 (same time as try with resources). It would appear that an exception from a try which is obscured by that in a finally isn't called suppressed in the JLS.
 
author & internet detective
Posts: 41593
883
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct. In the spirit of backward compatibility, suppressed exceptions are only when using try-with-resources. Added to errata.
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic