简体   繁体   English

在没有活动异常的情况下调用终止(引发捕获所有表达式)

[英]Terminate called without an active exception (throw in catch all expression)

I have a code block like this: 我有一个这样的代码块:

namespace bi = boost::intrusive;

struct Container {
    struct Item {
        bi::set_member_hook<> link;
        int x;
    };

    struct Cmp {
        bool opeartor()(Item const& it1, Item const &it2) const {
            return it1.x < it2.x;
        }
    };
    using Set = typename bi::set<Item,
                            bi::member_hook<Item, bi::set_member_hook<>, &Item::link>,
                            bi::compare<Cmp>,
                            bi::constant_time_size<false>
                            >;



    Container(Container const& o) {
        auto cloner = [](const Item &x) {
            return current_allocator().construct<Item>(x);
        };

        with_allocator(_alloctor, [&] {
            new (&_data) Set;

            _data.clone_from(o._data, cloner, current_deleter<Item>());
        }
    }


private:
    Set _data;
};

The program sometime terminated with this message: 该程序有时会终止,并显示以下消息:

terminate called without an active exception 在没有活动异常的情况下终止调用

I found an answer from stackoverflow that because of throw was called without an active exception. 我从stackoverflow找到了一个答案,因为在没有活动异常的情况下调用了throw But if without an active exception, then it can not reach the catch block. 但是,如果没有活动的异常,那么它将无法到达catch块。

I'm sorry for my bad English 对不起我的英语不好

EDIT: The code example was updated. 编辑:代码示例已更新。

EDIT 2: Correct the code as @:RemyLebeau recommended, and the bug still happen. 编辑2:按照@:RemyLebeau的建议更正代码,该错误仍然会发生。

I think the message 我认为讯息

terminate called without an active exception 在没有活动异常的情况下终止调用

actually takes to mean 实际上意味着

terminate called without an active C++ exception 在没有活动C ++异常的情况下终止调用

terminate() may be called for many different reasons, not limited to unhandled C++ exceptions. 可以出于许多不同的原因调用Terminate terminate() ,而不仅限于未处理的C ++异常。 The catch (...) clause only catches C++ exceptions. catch (...)子句仅捕获C ++异常。 In your particular case, terminate() may be called within allocate_memory() or clone() directly, or by runtime due to unhandled non-C++ exceptions (like some low-level Windows exceptions that should be captured with SEH ). 在您的特定情况下,由于未处理的非C ++异常(例如应使用SEH捕获的某些低级Windows异常),可以直接在allocate_memory()clone()或在运行时调用terminate() )。 In either case, the catch block is never entered. 无论哪种情况,都不会输入catch块。

You have called throw from catch but the catch was supposed to catch it. 您已将捕获称为“从捕获中抛出”,但捕获应该被捕获。 The throw should have been in try instead if I understood it correctly. 如果我正确理解的话,应该尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM