Custom Exceptions in C++

后端 未结 2 2001
暖寄归人
暖寄归人 2020-12-14 20:07

I\'ve been trying to make some custom exception classes for a C++ library I\'m working on. These custom exceptions capture extra info, such as file,line number,etc, needed f

2条回答
  •  情书的邮戳
    2020-12-14 21:04

    You should try boost::exception

    The purpose of Boost Exception is to ease the design of exception class hierarchies and to help write exception handling and error reporting code.

    It supports transporting of arbitrary data to the catch site, which is otherwise tricky due to the no-throw requirements (15.5.1) for exception types. Data can be added to any exception object, either directly in the throw-expression (15.1), or at a later time as the exception object propagates up the call stack.

    The ability to add data to exception objects after they have been passed to throw is important, because often some of the information needed to handle an exception is unavailable in the context where the failure is detected.

    Boost Exception also supports N2179-style copying of exception objects, implemented non-intrusively and automatically by the boost::throw_exception function.

提交回复
热议问题