0

我正在尝试在我的 C++ 应用程序中使用 v8。我被困在 helloworld 本身!

https://developers.google.com/v8/get_started上的 helloworld工作得很好。现在我试图在代码中捕获异常/错误。所以我使用了 TryCatch trycatch;。

int main(int argc, char *argv[]) {
    HandleScope handle_scope;
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);
    TryCatch trycatch; /* TO CATCH EXCETIONS/ERRORS */
    Handle<String> source = String::New("xyz();");
    Handle<Script> script = Script::Compile(source);
    Handle<Value> result = script->Run();
    if (result.IsEmpty()) {
        fprintf(stderr, "Exception: %s\n",
                *String::AsciiValue(trycatch.Exception()));
        return -1;
    }
    String::AsciiValue ascii(result);
    printf("%s\n", *ascii);
    context.Dispose();

    return 0;
}

异常被很好地捕获,但程序没有正确终止。它会产生分段错误。我究竟做错了什么?

4

1 回答 1

0

原来是一件愚蠢的事情。我早就安装了 libv8-dev 并忘记了它。现在我从源代码安装了 V8。所以我的系统上有两个版本的 V8。我卸载了 libv8-dev,问题已经解决。

于 2012-07-31T08:06:20.320 回答