}
CalledProcessError::CalledProcessError(ProcessReturnCode rc)
- : returnCode_(rc),
- what_(returnCode_.str()) {
-}
+ : SubprocessError(rc.str()), returnCode_(rc) {}
-SubprocessSpawnError::SubprocessSpawnError(const char* executable,
- int errCode,
- int errnoValue)
- : errnoValue_(errnoValue),
- what_(to<std::string>(errCode == kExecFailure ?
- "failed to execute " :
- "error preparing to execute ",
- executable, ": ", errnoStr(errnoValue))) {
+static inline std::string toSubprocessSpawnErrorMessage(
+ char const* executable,
+ int errCode,
+ int errnoValue) {
+ auto prefix = errCode == kExecFailure ? "failed to execute "
+ : "error preparing to execute ";
+ return to<std::string>(prefix, executable, ": ", errnoStr(errnoValue));
}
+SubprocessSpawnError::SubprocessSpawnError(
+ const char* executable,
+ int errCode,
+ int errnoValue)
+ : SubprocessError(
+ toSubprocessSpawnErrorMessage(executable, errCode, errnoValue)),
+ errnoValue_(errnoValue) {}
+
namespace {
// Copy pointers to the given strings in a format suitable for posix_spawn
/**
* Base exception thrown by the Subprocess methods.
*/
-class SubprocessError : public std::exception {};
+class SubprocessError : public std::runtime_error {
+ public:
+ using std::runtime_error::runtime_error;
+};
/**
* Exception thrown by *Checked methods of Subprocess.
public:
explicit CalledProcessError(ProcessReturnCode rc);
~CalledProcessError() throw() override = default;
- const char* what() const throw() override { return what_.c_str(); }
ProcessReturnCode returnCode() const { return returnCode_; }
private:
ProcessReturnCode returnCode_;
- std::string what_;
};
/**
public:
SubprocessSpawnError(const char* executable, int errCode, int errnoValue);
~SubprocessSpawnError() throw() override = default;
- const char* what() const throw() override { return what_.c_str(); }
int errnoValue() const { return errnoValue_; }
private:
int errnoValue_;
- std::string what_;
};
/**