Summary:
- This is pretty similar to some stuff that we already have in
Exception.h. Move (and rename) it.
Test Plan: - Unit tests
Reviewed By: simpkins@fb.com
FB internal diff:
D748313
#include <stdexcept>
#include <system_error>
+#include "folly/Conv.h"
#include "folly/Likely.h"
namespace folly {
throwSystemError(errno, msg);
}
+// Helper to throw std::system_error from errno and components of a string
+template <class... Args>
+void throwSystemError(Args... args) __attribute__((noreturn));
+template <class... Args>
+inline void throwSystemError(Args... args) {
+ throwSystemError(errno, folly::to<std::string>(args...));
+}
+
// Check a Posix return code (0 on success, error number on error), throw
// on error.
inline void checkPosixError(int err, const char* msg) {
#include <glog/logging.h>
#include "folly/Conv.h"
+#include "folly/Exception.h"
namespace folly {
namespace symbolizer {
length_(0),
baseAddress_(0) {
if (fd_ == -1) {
- systemError("open ", name);
+ folly::throwSystemError("open ", name);
}
struct stat st;
int r = fstat(fd_, &st);
if (r == -1) {
- systemError("fstat");
+ folly::throwSystemError("fstat");
}
length_ = st.st_size;
file_ = static_cast<char*>(
mmap(nullptr, length_, PROT_READ, MAP_SHARED, fd_, 0));
if (file_ == MAP_FAILED) {
- systemError("mmap");
+ folly::throwSystemError("mmap");
}
init();
}
uintptr_t baseAddress_;
};
-template <class... Args>
-void systemError(Args... args) __attribute__((noreturn));
-
-template <class... Args>
-void systemError(Args... args) {
- throw std::system_error(errno, std::system_category(),
- folly::to<std::string>(args...));
-}
-
template <class... Args>
inline void enforce(bool v, Args... args) {
if (UNLIKELY(!v)) {