序列化 GWT RPC 的 ANTLR 异常

发布于 2024-11-30 19:57:48 字数 611 浏览 5 评论 0原文

我正在使用 GWT-RPC 调用 ANTLR 语法。 如果语法失败,我将创建一个包含语法抛出的错误/异常的对象并将其返回给客户端。

当我这样做时,我得到了异常:

com.google.gwt.user.client.rpc.SerializationException: Type 'org.antlr.runtime.NoViableAltException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded.

我发现在 com.google.appengine.repackaged.org 中有一个相同的类,添加了一个公共无参数构造函数(GWT-RPC 序列化所需)。 antlr.runtime包。

如何将 org.antlr.runtime.NoViableAltException 转换为 com.google.appengine.repackaged.org.antlr.runtime.NoViableAltException

I am using GWT-RPC to call an ANTLR grammar.
If the grammar fails, I create an object containing the errors/exceptions that were thrown by the grammar and return it to the client.

When I do this I get the exception:

com.google.gwt.user.client.rpc.SerializationException: Type 'org.antlr.runtime.NoViableAltException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded.

I have found that there is an identical class with the addition of a public no argument constructor (needed for GWT-RPC serialization) in the com.google.appengine.repackaged.org.antlr.runtime package.

How do I convert the org.antlr.runtime.NoViableAltException into a com.google.appengine.repackaged.org.antlr.runtime.NoViableAltException?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

豆芽 2024-12-07 19:57:48

您需要例外本身吗?我认为不需要 - 您可能需要消息或最多堆栈跟踪。由于无论如何您都要重新打包异常,因此只需重新打包所需的字符串并通过网络发送它们即可。

Do you need the exceptions themselves? I'd think not - you probably need the message or at most the stack trace. Since you're repackaging the exceptions anyway, just repack the needed strings and send those over the wire.

暮光沉寂 2024-12-07 19:57:48

作为创建可序列化的新异常的替代方法,我让我的解析器重写了 BaseRecognizer 中的 emitErrorMessage 方法。

@members {
    @Override
    public void emitErrorMessage(String msg) {
        // The original prints to stdout.
        // You can do what you like with the message.
    }
}

正如塔索斯在他的回答中所建议的那样,我实际上并不需要例外,只需要其中的消息。

As an alternative for creating new Exceptions that can be serialized, I have made my Parser override the emitErrorMessage method from BaseRecognizer.

@members {
    @Override
    public void emitErrorMessage(String msg) {
        // The original prints to stdout.
        // You can do what you like with the message.
    }
}

As Tassos suggested in his answer, I did not actually need the exception, just the message from it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文