• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 74376
334
  • 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: 40798
829
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic