Class FramingException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
express.mvp.myra.transport.framing.FramingException
All Implemented Interfaces:
Serializable

public class FramingException extends RuntimeException
Exception thrown when message framing or deframing fails.

This exception indicates protocol-level errors in the framing layer, such as:

  • Oversized messages: Payload exceeds the configured maximum size
  • Invalid length prefix: The length field contains an invalid value (negative or zero when unexpected)
  • Corrupted frame: The frame structure doesn't match the expected format
  • Buffer overflow: Destination buffer is too small for the payload

Error Recovery

When a FramingException is caught, the connection should typically be closed because the byte stream may be in an inconsistent state. If the stream position is lost, it's generally not possible to resynchronize without application-level support.

Security Considerations

The maximum message size check is critical for preventing denial-of-service attacks. A malicious peer could send a frame with a very large length prefix, causing the receiver to allocate excessive memory. Implementations should validate length prefixes before any allocation.

Example

try {
    int payloadLength = framingHandler.deframeMessage(source, sourceLength, destination);
    // Process payload...
} catch (FramingException e) {
    logger.error("Framing error, closing connection: {}", e.getMessage());
    connection.close();
}
See Also:
  • Constructor Details

    • FramingException

      public FramingException(String message)
      Constructs a new framing exception with the specified detail message.
      Parameters:
      message - the detail message describing the framing error
    • FramingException

      public FramingException(String message, Throwable cause)
      Constructs a new framing exception with the specified detail message and cause.
      Parameters:
      message - the detail message describing the framing error
      cause - the underlying cause of the framing error
    • FramingException

      public FramingException(Throwable cause)
      Constructs a new framing exception with the specified cause.

      The detail message is set to (cause == null ? null : cause.toString()).

      Parameters:
      cause - the underlying cause of the framing error