使用TryCatch时v8 hello世界中的分段错误

Segmentation fault in v8 hello world when using TryCatch

本文关键字:分段 错误 世界 hello TryCatch v8 使用      更新时间:2023-10-16

我正试图在C++应用程序中使用v8。我被自己的世界困住了!

你好世界https://developers.google.com/v8/get_started效果很好。现在我正试图捕捉代码中的异常/错误。所以我使用了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: %sn",
                *String::AsciiValue(trycatch.Exception()));
        return -1;
    }
    String::AsciiValue ascii(result);
    printf("%sn", *ascii);
    context.Dispose();
    return 0;
}

异常捕获良好,但程序没有正确终止。它会生成分段错误。我做错了什么?

结果证明这是一件愚蠢的事情。我早就安装了libv8dev,却忘记了它。现在我从源代码安装了V8。所以我的系统上有两个版本的V8。我卸载了libv8dev,问题已经解决。