private HttpData encodeException(ServiceRequestContext ctx,
                                     RpcResponse reply,
                                     SerializationFormat serializationFormat,
                                     int seqId, String methodName, Throwable cause) {

        final TApplicationException appException;
        if (cause instanceof TApplicationException) {
            appException = (TApplicationException) cause;
        } else {
            if (ctx.config().verboseResponses()) {
                appException = new TApplicationException(
                        TApplicationException.INTERNAL_ERROR,
                        "\n---- BEGIN server-side trace ----\n" +
                        Exceptions.traceText(cause) +
                        "---- END server-side trace ----");
            } else {
                appException = new TApplicationException(TApplicationException.INTERNAL_ERROR);
            }

            // Causes are not sent over the wire but just used for RequestLog.
            appException.initCause(cause);
        }

        final ByteBuf buf = ctx.alloc().buffer(128);
        boolean success = false;
        try {
            final TTransport transport = new TByteBufTransport(buf);
            final TProtocolFactory protocolFactory = responseProtocolFactories.get(serializationFormat);
            assert protocolFactory != null;
            final TProtocol outProto = protocolFactory.getProtocol(transport);
            final TMessage header = new TMessage(methodName, TMessageType.EXCEPTION, seqId);
            outProto.writeMessageBegin(header);
            appException.write(outProto);
            outProto.writeMessageEnd();

            ctx.logBuilder().responseContent(reply, new ThriftReply(header, appException));

            final HttpData encoded = HttpData.wrap(buf);
            success = true;
            return encoded;
        } catch (TException e) {
            throw new Error(e); // Should never reach here.
        } finally {
            if (!success) {
                buf.release();
            }
        }
    }
Returns the default {@link SerializationFormat} of this service.
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/THttpService.java