Sometimes, you want a flexible way to handle certain situations involving C++ exceptions, particularly those for which alternative actions are either easily encapsulated, do not substantially interrupt the program flow, or must cross a foreign-function interface or thread boundary.
A useful idiom is to rewrite attempts to perform an action with such forms of exception handling as instead returning a monadic value, like with C++17's std::optional<>:
// Given: string read_first_line(const string&); string handle_read_error(std::exception&); // Construct a new function: auto first_line_reader = attempt(read_first_line, handle_read_error); // Usage: auto first_line = first_line_reader("input.txt"); if(first_line) cout << *first_line << '\n';
It's useful to compare this with both traditional exception handling and Lippincott functions.
For purposes of crossing FFI or thread boundaries, consider the possibility of writing a function that strictly forwards parameters into the local code, and then strictly returns it's optional<T> value-- it never leaves any possibility of an exception leaking (which generally means a crash).
The github page is here.
This project is one of its kind!