How do I handle a server error in the middle of an Http message?

Assuming I already sent the header of the message and I am streaming the the body of the message, what do I do when I encounter an unexpected error.

I am also assuming this error was caused while generating the content and not a connection error.

(Greatly) Simplified Code:

// I can define any transfer encoding or header fields i need to.
send(header);  // Sends the header to the Http client.

// Using an iterable instead of stream for code simplicity's sake.
Iterable<String> stream = getBodyStream();
Iterator<String> iterator = stream.iterator();

while (iterator.hasNext()) {
    String string;
    try {
       string = iterator.next();   
    catch (Throwable error) { // Oops! an error generating the content.
        // What do i do here? (In regards to the Http protocol)
    }

    send(string);
}

Is there a way to tell the client the server failed and should either retry or abandon the connection or am I sool?

The code is greatly simplified but I am only asking in regards to the protocol and not the exact code.

Thank You

Edit
Report