• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

Sybex 816. Chapter 5 possible error

Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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.
Posts: 71028
  • Mark post as helpful
  • send pies
  • 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: 40283
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • 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.
Ever since I found this suit I've felt strange new needs. And a tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic