Class ChannelClosedException

All Implemented Interfaces:
Serializable

public class ChannelClosedException extends IllegalStateException
Thrown when an AsyncChannel operation is attempted after the channel has been closed.

This exception is raised in the following situations:

  • send() — the channel was closed before or during the send attempt. Pending senders that were waiting for buffer space when the channel closed also receive this exception.
  • receive() — the channel was closed and all buffered values have been drained. Values buffered before closure are still delivered. A failure passed to AsyncChannel.close(Throwable) is this exception's cause, not a different exception type. A hand-written loop must read that cause.

When used with for await, a plain for, each, collect or toList, a close with no cause ends iteration. A close that carries a cause throws that cause after the values already sent. The code that reads the channel writes the try/catch:

 def ch = AsyncChannel.create()
 // ... producer sends values, then calls ch.close()
 for await (item in ch) {
     process(item)       // processes all buffered values
 }
 // loop exits cleanly after the channel is closed and drained
 
A Java enhanced for calls Iterator.hasNext(), which may throw a checked exception that Iterator does not declare.
Since:
6.0.0
See Also:
  • Constructor Details

    • ChannelClosedException

      public ChannelClosedException(String message)
      Creates a ChannelClosedException with the specified detail message.
      Parameters:
      message - the detail message describing which operation failed
    • ChannelClosedException

      public ChannelClosedException(String message, Throwable cause)
      Creates a ChannelClosedException with the specified detail message and cause.
      Parameters:
      message - the detail message
      cause - the underlying cause (e.g., an InterruptedException if the thread was interrupted while waiting on a channel operation)