Package groovy.concurrent

# Class ChannelClosedException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.IllegalStateException
groovy.concurrent.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. Note that values buffered before closure are still delivered normally; only once the buffer is exhausted does this exception appear.

When used with `for await`, the loop infrastructure translates `ChannelClosedException` into a clean end-of-stream signal (i.e., the loop exits normally rather than propagating the exception):

     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

Since:
  6.0.0
See Also:
  - `AsyncChannel.send(Object)`
  - `AsyncChannel.receive()`
  - `AsyncChannel.close()`
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ChannelClosedException(String message)`
  Creates a `ChannelClosedException` with the specified detail message.
  `ChannelClosedException(String message, Throwable cause)`
  Creates a `ChannelClosedException` with the specified detail message and cause.

- ## Method Summary

  ### Methods inherited from class java.lang.Throwable

  `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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)