What exceptions does boost::process::child throw?

401 views Asked by At

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

1

There are 1 answers

2
alagner On

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.