concept exception in category c++

This is an excerpt from Manning's book C++ Concurrency in Action, Second Edition.
So, you might not have a pop() operation yet, but you can quickly check push() for compliance with the guidelines. The only place that can throw an exception is the construction of the new node 1, but this will clean up after itself, and the list hasn’t been modified yet, so that’s perfectly safe. Because you build the data to be stored as part of the node, and you use compare_exchange_weak() to update the head pointer, there are no problematic race conditions here. Once the compare/exchange succeeds, the node is on the list and ready for the taking. There are no locks, so there’s no possibility of deadlock, and your push() function passes with flying colors.
Throws An exception of type std::system_error if an error occurs.

This is an excerpt from Manning's book Functional Programming in C++.
Listing 6.5 Efficient cache for calculating Fibonacci numbers
class fib_cache { public: fib_cache() : m_previous{0} #1 , m_last{1} #1 , m_size{2} #2 { } size_t size() const { return m_size; } unsigned int operator[] (unsigned int n) const { return n == m_size - 1 ? m_last : #3 n == m_size - 2 ? m_previous : #3 0; #3 } void push_back(unsigned int value) { m_size++; #4 m_previous = m_last; #4 m_last = value; #4 } }; #1 Start of the Fibonacci series: {0, 1} #2 Size of the cache (not excluding the forgotten values) #3 Returns the requested numbers if they’re still in the cache. Otherwise, returns 0. Alternatively, you could throw an exception. #4 Adds a new value to the cache, and increases the size
To implement the program state by using
std::variant, you can reuse the definitions of theinit_t,running_t, andfinished_tclasses, with the exception that you don’t need them to be subclasses of some common type, and you don’t need to create integer tags for them:
Figure 10.11 To perform error handling with optional values instead of exceptions, you can chain functions that return optional values with
mbind. The chain will be broken as soon as any of the transformations fails and returns an empty optional. If all the transformations succeed, you’ll get an optional containing the resulting value.![]()