Project Coin: Uniform Suppression in try-with-resources

As previously considered, the specification of the try-with-resources statement has been updated to require uniform suppression of all throwables. That is, the semantics of the code around the implicitly generated calls to close was previously

    try {
      #resource.close();
    } catch(Exception #suppressedException) {
      #primaryException.addSuppressedException(#suppressedException);
    }

and has been replaced with

    try {
      #resource.close();
    } catch(Throwable #suppressedException) {
      #primaryException.addSuppressedException(#suppressedException);
    }

(The initial implementation actually implemented the latter semantics; a test has been added to verify the behavior.)

Comments:

Joe: this is being really picky, but don't name a variable (or method) that can be a Throwable with an Exception in its name. Specifically, for the new code semantics that you suggest, use

try {
#resource.close();
} catch(Throwable #suppressedThrowable ) {
#primaryThrowable.addSuppressedThrowable (#suppressedThrowable );
}

There are a few places in the JDK standard libraries where they do that and it drives me nuts!

Posted by Brent on August 18, 2010 at 01:14 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

darcy

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News

No bookmarks in folder

Blogroll