草庐IT

objc_exception_throw

全部标签

c++ - 结合使用 -fno-unwind-tables 和 -fno-exceptions

除了-fno-exceptions之外,使用-fno-unwind-tables有什么好处——尤其是在(独立的)C++嵌入式系统上?根据PracticalGuidetoBareMetalC++—§Exceptions应该同时使用:Itispossibletoforbidusageofthrowstatementsbyprovidingcertainoptionstothecompiler.ForGNUcompiler(gcc)pleaseuse-fno-exceptionsinconjunctionwith-fno-unwind-tablesoptions.但是没有解释-fno-unw

c++ - 使用 throw() 说明符模拟方法

我正在尝试通过Google模拟一个具有throw()说明符的虚拟方法。原始函数如下所示:virtualReturnValueFunctionName()constthrow();我收到编译器错误:looserthrowspecifierfor'virtualFunctionSignature'这是我到目前为止尝试过的代码:MOCK_CONST_METHOD0(FunctionName,ReturnValue());MOCK_CONST_METHOD0(FunctionName,ReturnValue()throw());MOCK_CONST_METHOD0(FunctionName,R

c++ - 使用 throw_with_nested 并捕获嵌套异常

我真的很喜欢c++11中的std::throw_with_nested,因为它模拟了java的printStackTrace()但现在我只是好奇如何捕获嵌套异常,例如:voidf(){try{throwSomeException();}catch(...){std::throw_with_nested(std::runtime_error("Insidef()"));}}voidg(){try{f();}catch(SomeException&e){//IwanttocatchSomeExceptionhere,notstd::runtime_error,:(//dosomething

c++ - 我可以/我应该使用 std::exception 进行常规错误处理吗?

我打算用C++开始这个新项目,并且正在考虑一种不痛苦的错误处理方法。现在,我不会开始抛出和捕获异常,并且很可能永远不会抛出异常,但我在想-即使是常规错误处理,为什么要自己滚动/复制粘贴一个类来描述错误/状态,当我可以使用std::exception及其子类(或者可能是std::optional)?usingStatus=std::optional;StatussomethingThatMayFail(intx);是否有人/任何项目以这种方式工作?这是一个荒谬的想法还是有点不可靠? 最佳答案 我不认为你应该构造异常,除非你真的打算抛出

c++ - 为什么在 void 函数中接受 return throw std::exception()?

我在return之后错误地粘贴了一个throw语句,最终结果如下:voidDXManager::initialize(conststd::shared_ptr&ctx_ptr){//...if(FAILED(result)){returnthrowstd::exception("Failedtoenumeratedisplaymodelist");}//...}我在注意到错误之前成功构建了解决方案,我很好奇哪个规范允许上述语法。通过阅读cppreference.com(在注释下),我明白了Thethrow-expressionisclassifiedasprvalueexpressio

c++ - throw 或 delete 表达式可以依赖吗?

gcc5.0和clang3.6都需要typename以下示例中的关键字:templatestructB{typedefintType;};templatestructA{typedeftypenameB::TypeThrow;typedeftypenameB::TypeDelete;};C++11标准中的以下措辞涵盖了这一点:[except]/2Athrow-expressionisoftypevoid.[expr.delete]/1Theoperandshallhaveapointertoobjecttype,oraclasstypehavingasinglenon-explicit

c++ - rethrow_exception 真的可以抛出相同的异常对象,而不是一个拷贝吗?

在检查exception_ptr的作用时,C++11标准指出(18.8.5/7):Useofrethrow_exceptiononexception_ptrobjectsthatrefertothesameexceptionobjectshallnotintroduceadatarace.[Note:ifrethrow_exceptionrethrowsthesameexceptionobject(ratherthanacopy),concurrentaccesstothatrethrownexceptionobjectmayintroduceadatarace...我没有发现这个奇怪

c++ - 为什么我不能在 Exception 类中有 auto_ptr

我在异常类中遇到了auto_ptr的问题,我最终将其简化为:#includeclassMyException{std::auto_ptrm_foo2;};intmain(){try{throwMyException();}catch(constMyException&){}return0;}编译失败:/perforce/unstable/test/Common/Exceptions/TestException4.cpp:Infunction'intmain()':/perforce/unstable/test/Common/Exceptions/TestException4.cpp:1

c++ - 什么时候使用 uncaught_exception?

什么是uncaught_exception的好用例? 最佳答案 HerbSutter似乎给出了很好的建议here.他不知道它有什么好的用途,并说在某些情况下它看起来很有用,但实际上并没有用。 关于c++-什么时候使用uncaught_exception?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/275249/

c++ - 如何摆脱 "C++ exception specification ignored"警告

最近得到一个别人实现过的dll。我必须在我的应用程序中使用它。在他们类的头文件中,他们有函数声明voidfunc1()throw(CCustomException);现在当我编译它时收到警告,C++exceptionspecificationignoredexcepttoindicateafunctionisnot_declspec(nothrow)我读了MSDN-Documentation但无法清楚地理解它。另外,我不想仅仅因为它出现就禁用警告。我想知道我做错了什么而不是禁用它。我想我的函数,说myfunc()从dll访问那个func1()没有那个异常规范列表。因此,我也尝试在我的函