/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#ifndef FOLLY_EXCEPTIONWRAPPER_H
-#define FOLLY_EXCEPTIONWRAPPER_H
+#pragma once
#include <cassert>
#include <exception>
+#include <iostream>
#include <memory>
-#include <folly/String.h>
+#include <folly/ExceptionString.h>
#include <folly/detail/ExceptionWrapper.h>
namespace folly {
assign_eptr(eptr);
}
- void throwException() const {
+ // If the exception_wrapper does not contain an exception, std::terminate()
+ // is invoked to assure the [[noreturn]] behaviour.
+ [[noreturn]] void throwException() const {
if (throwfn_) {
throwfn_(item_.get());
} else if (eptr_) {
std::rethrow_exception(eptr_);
}
+ std::cerr
+ << "Cannot use `throwException` with an empty folly::exception_wrapper"
+ << std::endl;
+ std::terminate();
}
explicit operator bool() const {
bool>::type
with_exception(F f) const {
try {
- throwException();
+ if (*this) {
+ throwException();
+ }
} catch (typename std::decay<Ex>::type& e) {
f(e);
return true;
}
try {
- throwException();
+ if (*this) {
+ throwException();
+ }
} catch (...) {
return std::current_exception();
}
}
};
}
-#endif