    public static {{ return_type }} {{ method_name }}({{ params }}) throws {{ exception_class }} {
        try (var arena = Arena.ofShared();
             var bridge = new VisitorBridge({{ visitor_arg }})) {
            {{ marshal_body }}

            var visitorHandle = (MemorySegment) NativeLib.{{ prefix_upper }}_VISITOR_CREATE.invoke(bridge.callbacksStruct());
            if (visitorHandle.equals(MemorySegment.NULL)) {
                throw new {{ exception_class }}("Failed to create visitor handle", null);
            }

            try {
                {{ invoke_body }}
            } catch (Throwable e) {
                throw new {{ exception_class }}("FFI call failed", e);
            } finally {
                NativeLib.{{ prefix_upper }}_VISITOR_FREE.invoke(visitorHandle);
                bridge.rethrowVisitorError();
            }
        } catch ({{ exception_class }} e) {
            throw e;
        } catch (Throwable e) {
            throw new {{ exception_class }}("FFI call failed", e);
        }
    }
