Project

General

Profile

Actions

Feature #4834

closed

NDN_THROW: improved replacement for BOOST_THROW_EXCEPTION

Added by Junxiao Shi almost 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Category:
Utils
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:

Description

BOOST_THROW_EXCEPTION is quite inflexible for our use cases. Since our exception types do not derive from boost::exception, in order to augment the thrown exception with additional error_info structs, each user has to wrap the constructed exception in a boost::enable_error_info call.

I'm proposing NDN_THROW as an improved alternative and drop-in replacement for BOOST_THROW_EXCEPTION. Some of the improvements over its boost counterpart are:

  • Easy chaining of error_info structs to transport arbitrary types to the catch site, e.g.:
    NDN_THROW(std::runtime_error("foo")) << my_error_info("bar") << more_info(42);
  • On platforms with boost >= 1.65, automatically embeds a stack trace up to the throw site, which can be inspected or printed at the catch site.
  • Additional _ERRNO and _NESTED variants, that automatically capture the value of errno and the active exception (to be nested in the new exception), respectively. These two macros substantially reduce repeated boilerplate code when dealing with C library functions and nested exceptions.
  • Fully compatible with boost::diagnostic_information and boost::current_exception.
  • Much shorter macro name :)
Actions

Also available in: Atom PDF