Project

General

Profile

Feature #4834

Updated by Davide Pesavento almost 6 years ago

`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.: 

 ```cpp 
     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 :)

Back