Add more constructors in ClosedChannelException

Alan Bateman Alan.Bateman at
Tue Jan 24 08:04:57 UTC 2023

On 24/01/2023 06:14, Aayush Atharva wrote:
> Hello JDK Community! 🙂
> The current ClosedChannelException does not have any constructors to 
> pass a message. We have to rely on 'initCause(...)'​ for passing extra 
> messages regarding a ClosedChannelException but it's not a very good 
> practice in my opinion. Because we will have to generate another 
> Exception which will create another brand-new object in the heap and 
> generates a stack trace. And all of this just to pass a simple message 
> for ClosedChannelException.
Can you bring this to nio-dev to discuss? Most of the exceptions that 
JSR-51 defined in that package are very specific. In this case, 
ClosedChannelException just means the channel is closed. Its subclasses 
AsynchronousCloseException and ClosedByInterruptException are for the 
more specific cases. Adding new constructors with messages/causes to 
support other usages might be okay but it shouldn't be done in isolation 
without creating an inconsistency in that package so it would have to 
looked at in the whole.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the discuss mailing list