0

我有一个关于 Javascript 引擎错误的问题。这可能是一个非常具体的问题,以前有没有人看到过这个错误?请你帮忙看看好吗?

这是错误消息:

483e709e1e8:buildDirARNJavaScriptEngine mac$ make install
Scanning dependencies of target JavaScriptEngine
[  8%] Building CXX object JavaScriptEngineImpl/src/CMakeFiles/JavaScriptEngine.dir/JavaScriptEngineImpl.cpp.o
[ 16%] Building CXX object JavaScriptEngineImpl/src/CMakeFiles/JavaScriptEngine.dir/JavaScriptEngineImplDuktape.cpp.o
/Users/mac/Documents/WorkSpace/JavaScriptEngine/JavaScriptEngineImpl/src/JavaScriptEngineImplDuktape.cpp:130:13: error: '~DuktapeStackVerification' has
      a non-throwing exception specification but can still throw [-Werror,-Wexceptions]
            throw utils::Exception(errorMsg);
            ^
/Users/mac/Documents/WorkSpace/JavaScriptEngine/JavaScriptEngineImpl/src/JavaScriptEngineImplDuktape.cpp:123:6: note: destructor has a implicit
      non-throwing exception specification
     ~DuktapeStackVerification() {
     ^
1 error generated.
make[2]: *** [JavaScriptEngineImpl/src/CMakeFiles/JavaScriptEngine.dir/JavaScriptEngineImplDuktape.cpp.o] Error 1
make[1]: *** [JavaScriptEngineImpl/src/CMakeFiles/JavaScriptEngine.dir/all] Error 2
make: *** [all] Error 2

这是我构建的内容/方式:

a483e709e1e8:buildDirJavaScriptEngine mac$ cmake ../JavaScriptEngine/ -DWITH_DUKTAPE=ON -DWITH_V8=ON
Creating the build directory for the JavaScriptEngineLibrary with build type: DEBUG
CMAKE_INSTALL_PREFIXis=====/Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts
====> Exporting Target Tuple using /Users/mac/Documents/WorkSpace/JavaScriptEngine/../BuildCommons/cmake/config.guess
====> Target Tuple is x86_64-apple-darwin18.7.0
Dependencies SHARED +++++ /Users/mac/Documents/WorkSpace/Artifacts/lib/libLogger.dylib;-Wl,-rpath,/Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts/lib
Dependencies SHARED +++++ /Users/mac/Documents/WorkSpace/Artifacts/lib/libException.dylib;-Wl,-rpath,/Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts/lib
Dependencies SHARED +++++ /Users/mac/Documents/WorkSpace/Artifacts/lib/libJsonContainer.dylib;-Wl,-rpath,/Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts/lib
Dependencies +++++ /Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts/include;/Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts/include/v8
Dependencies SHARED +++++ /Users/mac/Documents/WorkSpace/Artifacts/lib/libDuktape.dylib;-Wl,-rpath,/Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine/../Artifacts/lib
Dependencies STATIC +++++ /Users/mac/Documents/WorkSpace/Artifacts/lib/libv8_monolith.a
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mac/Documents/WorkSpace/buildDirJavaScriptEngine

这段源代码抱怨:

~DuktapeStackVerification() {
    m_endStackIndex = duk_get_top_index(m_ctx);
    if (m_beginStackIndex != m_endStackIndex) {
        std::string errorMsg = "beginStackIndex: " + std::to_string(m_beginStackIndex) +
                               " endStackIndex: " + std::to_string(m_endStackIndex) +
                               " func: " + m_func;
        LOG_ERROR(errorMsg, JAVASCRIPTENGINE_IMPL_DUKTAPE_MODULE_NAME);
        throw utils::Exception(errorMsg);
    }
}
4

1 回答 1

1

编译器实际上是在告诉你发生了什么:

error: '~DuktapeStackVerification' has a non-throwing exception specification but can still throw

note: destructor has a implicit non-throwing exception specification

对于其他背景,您可以搜索“C++ throw destructor”之类的术语,您会发现(例如herehere)从 C++11 开始,析构函数被隐式标记nothrow(true),因为从析构函数中抛出通常被认为是危险的。要覆盖该默认值,您必须将析构函数显式注释为noexcept(false)-- 或者干脆停止在那里抛出,并使用其他一些机制来发出问题的信号。无论如何,它看起来像是针对编程错误的断言,因此立即终止可能与抛出异常一样好。

于 2019-08-28T08:48:19.110 回答