1 min readMar 19, 2018
You’re perfectly right, there are bugs in my implementation. After some thoughts I realized, that NonFatal extractor complicates everything, because control exception (InterruptedException) and fatal exceptions are mixed there.
It’s kind of incorrect to do on close in catch:
case NonFatal(e2) => e1.addSuppressed(e2)
case e2 =>
e2.addSuppressed(e1)
throw e2
Because if both exceptions are “fatal” it’s important to choose which one to throw. But this algorithm is kind of tricky and maybe depend on a use case.
In java’s try-with-resources it’s simpler, because they don’t care about “fatalness”, therefore they do it very straightforward.