2

In the process tutorial, it states

The default behaviour of all functions is to throw an std::system_error on failure.

However, the example given is using boost::process::system. Do boost::process::child functions throw a std::system_error the way boost::system functions do? Where could I find this information in future for other classes? It's not part of the class documentation

Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
Cecilia
  • 4,512
  • 3
  • 32
  • 75
  • 1
    Since capturing should be by reference almost always, maybe they mean that they throw a `system_error` in the sense that you should capture by `system_error&`. And `process_error` (derived from it) is just an implementation detail. – alfC Mar 15 '23 at 07:10

1 Answers1

2

Tutorial indeed states std::system_error while reference docs state this:

namespace boost {
  namespace process {
    struct process_error;
  }
}

Code inspection is the ultimate answer (boost/process/exception.hpp):

namespace boost
{
namespace process
{
///The exception usually thrown by boost.process.
/** It merely inherits [std::system_error](http://en.cppreference.com/w/cpp/error/system_error)
 * but can then be distinguished in the catch-block from other system errors.
 *
 */
struct process_error : std::system_error
{
    using std::system_error::system_error;
};

}
}

If a function marked noexcept throws, std::terminate is called; effectively this allows to simplify the reasoning about them as generally non-throwing ones. Otherwise, i.e. without noexcept or with noexcept(false), a function can throw anything. In the end it is up to the programmer to believe the specification or not.

alagner
  • 3,448
  • 1
  • 13
  • 25