English 中文(简体)
一种办法是处理规则渔获量中的所有硬性例外类型。 路障
原标题:is there a way to handle all antlr exception types in a rule catch[...] block

I m使用ANTLR3, 时间为C。

我愿处理一些习俗错误。 我真的说是,如果在一项次级规则中存在某种类型的ant子配对例外,那么我就要告诉《南极海生力量》试图处理它,让它遵守一个更加全球性的规则。

按照这一规则,我会这样做,然后试图恢复。

我制定了这样的规则集权方法,以便所有规则都胜过。

@rulecatch 
{
    if (HASEXCEPTION())
    {
    PREPORTERROR();
    }
}

这使我能够根据想要的规则插入渔获量处理器。

按照我的利益规则,我可以这样利用渔获物:

catch [ANTLR3_RECOGNITION_EXCEPTION]
{
    PREPORTERROR();
    RECOGNIZER->consumeUntil(RECOGNIZER,RCURLY);
    CONSUME();
    PSRSTATE->error = ANTLR3_FALSE;
    PSRSTATE->failed = ANTLR3_FALSE;
     }

问题是,这一辛迪加似乎只允许我追捕一种例外情况。 我愿赶上所有例外情况。

是否有办法这样做?

我认为,我可以超负荷履行所有恢复职能,但有些法典会产生例外:

                    CONSTRUCTEX();
                    EXCEPTION->type         = ANTLR3_NO_VIABLE_ALT_EXCEPTION;
                    EXCEPTION->message      = (void *)"";
                    EXCEPTION->decisionNum  = 23;
                    EXCEPTION->state        = 0;


                    goto rulewhenEx;

意 见 我需要抓住所有可能的例外情况。

任何想法?

最佳回答

我最后试图为此找到两个解决办法。

方法1

Overloading the rulecatch setting to set the exception type to one specific type

@rulecatch 
{
    if (HASEXCEPTION())
    {

    // This is ugly.  We set the exception type to ANTLR3_RECOGNITION_EXCEPTION so we can always
    // catch them.
    PREPORTERROR();
    EXCEPTION->type = ANTLR3_RECOGNITION_EXCEPTION;
    }
}

This allows me to use one catch block as all exceptions will be of that type.

Approach 2)

I just use multiple catch blocks and they all dispatch to a common function to handle the error

catch [ANTLR3_RECOGNITION_EXCEPTION]
{
    handleException();
}
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
    handleException();
}
....
问题回答

暂无回答




相关问题
Separating Business Layer Errors from API errors

The title is horrible, i know; I m terrible at titles on SO here. I m wondering what would be the best way to present unified error responses in a webapi when errors could be raised deep inside the ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

How to tell why a file deletion fails in Java?

File file = new File(path); if (!file.delete()) { throw new IOException( "Failed to delete the file because: " + getReasonForFileDeletionFailureInPlainEnglish(file)); } Is there a ...

Exceptions: redirect or render?

I m trying to standardize the way I handle exceptions in my web application (homemade framework) but I m not certain of the "correct" way to handle various situations. I m wondering if there is a ...

热门标签