草庐IT

child_exception

全部标签

c++ - 如何初始化boost::process::child(boost process 0.5)?

我想存储boost::process的子进程,但不知道如何初始化它操作系统:win764位编译器:msvc200832位boost:1_55_0简化后的例子#include#include#include#includevoidtest_boost_system(){namespacebp=boost::process;namespacebpi=boost::process::initializers;//bp::childchild;//#1boost::system::error_codeec;bp::childchild_2=bp::execute(bpi::run_exe("l

c++ - 没有匹配的成员函数来调用 child.value

当我尝试编译下面的代码时出现错误:src/main.cpp:51:48:error:nomatchingmemberfunctionforcallto'child_value'std::cout我不明白的是我能够在上面的循环中使用它。我只能假设它希望我使用kv.second.child_value(kv.second);代替。但是我希望它在for(auto&eb:mapb){.返回的xml上运行这段代码。#include"pugi/pugixml.hpp"#include#include#includeintmain(){conststd::maptagMap{{"descriptio

c++ - 在这个例子中,std::variant 是如何变成 valueless_by_exception 的?

这是受cppreference中示例启发的示例structS{operatorint(){throw42;}};intmain(){variantv{12.f};//OKcout(S());//vmaybevalueless}catch(...){}cout对于一个编译器,我试过它的输出false,true意味着emplace导致变体变得毫无值(value)我不明白这是怎么发生的。特别是我根本不明白为什么emplace被调用,我希望程序甚至不会调用它,因为从S到int参数的转换会抛出。 最佳答案 注意相关std::variant::

C++ fstream : throwing exception when reaching eof

我想读取两个文件,直到读到其中一个文件的末尾。如果出现问题,fstream应该抛出异常。问题是,设置eof位时也会设置坏位或失败位。ifstreaminput1;input1.exceptions(ios_base::failbit|ios_base::badbit);input1.open("input1",ios_base::binary|ios_base::in);ifstreaminput2;input2.exceptions(ios_base::failbit|ios_base::badbit);input2.open("input2",ios_base::binary|io

c++ - 如何将消息附加到 std::exception?

我想做以下事情:std::stringfileName="file";std::ifstreamin(fileName.c_str());in.exceptions(std::istream::failbit);try{loadDataFrom(in);}catch(std::ios_base::failure&exception){std::stringlocation=std::string("infile\n")+fileName;//appendthe"location"totheerrormessage;throw;}如何将错误消息附加到异常? 最

c++ - 安置新的和异常(exception)

“placementnew”运算符声明如下:void*operatornew(std::size_tsize,void*ptr)noexcept;但是虽然它不涉及任何实际分配,因此消除了错误的分配异常,但指针仍然可能指向错误的位置,在这种情况下,人们会期望得到一个范围或溢出/下溢错误,但是它被声明为noexcept的事实不会直接终止执行吗?这是否也意味着在C++11之前放置new将抛出并尝试处理std::unexpected而不是直接处理std::set_unexpected崩溃?“以防万一”,难道不应该有大量的placementnew吗? 最佳答案

c++ - boost::exception 和 std::exception 之间的关系

假设有如下代码:try{//Dosomebooststuffhere}catch(conststd::exception&stdEx){cout问题:1)我知道代码适用于某些boost异常,即使std::exception和boost::exception不在同一个继承路径上。为什么它会起作用?2)它是否适用于所有boost异常?换句话说,是否有可以触发低于std::exception处理程序的boost::exception处理程序的示例? 最佳答案 如您所说,boost::exception不是从std::exception派生

c++ - 避免使用 "child"延迟 `operator<<` 对象构造

假设我有一个存储std::vector的容器对象多态child。structChild{Child(Parent&mParent){/*...*/}virtual~Child(){}};classParent{private:std::vector>children;templateauto&mkChild(TArgs&&...mArgs){//`static_assert`that`T`isderivedfrom`Child`...children.emplace_back(std::make_unique(std::forward(mArgs)...));return*childr

c++ - std::current_exception 是否应该从类的析构函数中的 catch block 返回非空

我和我的同事认为我们在VisualC++2012和2013中发现了一个错误,但我们不确定。以下代码中对std::current_exception的调用是否应该返回一个非空的exception_ptr?似乎在我们尝试过的大多数其他编译器上:#include#include#includeclassA{public:~A(){try{throwstd::runtime_error("ohno");}catch(std::exception&){std::clog在VisualC++下运行时,我们得到“0”(假,这意味着返回的exception_ptr为空)。其他编译器,例如g++,打印“

c++ - boost 测试 : catch user defined exceptions

如果我的代码中有用户定义的异常,我将无法进行Boost测试将它们视为失败。例如,BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MyTest,1)BOOST_AUTO_TEST_CASE(MyTest){//codewhichthrowsuserdefinedexception,notderivedfromstd::exception.}我收到一条通用消息:Caughtexception:....unknownlocation(0):....它不会将此错误识别为失败,因为它不是std::exception。所以它不遵守expected_failures条款