C ++“在'之前预期的primary-expression'('token'错误

时间:2011-05-24 19:11:04

标签: c++ compiler-errors

我有这段代码:

FILE *f = fopen(intPath, "r");
Node *n;
if (f) {
    try {
        n = parse(f, intPath);
    } catch (SyntaxError e) {
        fclose(f); /***** line 536 *****/
        throw LangException(
            builtin_classes::exception_class::create_ImportError(
                String::fromAscii(e.filename)->
                append(String::fromAscii(":"))->
                append(String::fromInt(e.line))->
                append(String::fromAscii(":"))->
                append(String::fromInt(e.col))->
                append(String::fromAscii(": syntax error: "))->
                append(String::fromAscii(e.message))
        );
    }
    fclose(f);
    return n->eval(scope);
} else {
    throw LangException(
        builtin_classes::exception_class::create_ImportError(
            String::fromAscii("failed to open file for reading")
        ),
        line,
        col
    );
}

编译器给出了这个错误:

  

nodes.cpp:537:40:错误:‘(’令牌之前的预期primary-expression
  nodes.cpp:544:94:错误:‘)’令牌之前预期‘;’

我不知道它可能是什么,特别是因为该代码示例具有另一个执行相同操作的语句,并且它不会导致错误。

4 个答案:

答案 0 :(得分:5)

throw LangException(
   builtin_classes::exception_class::create_ImportError(
      String::fromAscii(e.filename)->
      append(String::fromAscii(":"))->
      append(String::fromInt(e.line))->
      append(String::fromAscii(":"))->
      append(String::fromInt(e.col))->
      append(String::fromAscii(": syntax error: "))->
      append(String::fromAscii(e.message))
   )  // This closes the function call
; // You didn't close the throw here!

答案 1 :(得分:3)

您的()与那个较大的第一个throw LangException区块不匹配。

答案 2 :(得分:2)

编译器告诉你出了什么问题。 throw LangException(没有)

答案 3 :(得分:2)

究竟是什么意思。您在该行的‘)’令牌之前缺少‘;’

LangException(...

未关闭。