proxygen
Exception.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <exception>
20 
21 #include <folly/CPortability.h>
22 #include <folly/CppAttributes.h>
23 #include <folly/Portability.h>
24 
25 namespace folly {
26 
31 template <typename Ex>
32 [[noreturn]] FOLLY_NOINLINE FOLLY_COLD void throw_exception(Ex&& ex) {
33 #if FOLLY_HAS_EXCEPTIONS
34  throw static_cast<Ex&&>(ex);
35 #else
36  (void)ex;
37  std::terminate();
38 #endif
39 }
40 
44 template <typename Ex>
45 [[noreturn]] FOLLY_NOINLINE FOLLY_COLD void terminate_with(Ex&& ex) noexcept {
46  throw_exception(static_cast<Ex&&>(ex));
47 }
48 
49 // clang-format off
50 namespace detail {
51 template <typename T>
53  return static_cast<T&&>(t);
54 }
55 template <std::size_t N>
57  char const (&array)[N]) {
58  return static_cast<char const*>(array);
59 }
60 template <typename Ex, typename... Args>
61 [[noreturn]] FOLLY_NOINLINE FOLLY_COLD void throw_exception_(Args&&... args) {
62  throw_exception(Ex(static_cast<Args&&>(args)...));
63 }
64 template <typename Ex, typename... Args>
66  Args&&... args) noexcept {
67  throw_exception(Ex(static_cast<Args&&>(args)...));
68 }
69 } // namespace detail
70 // clang-format on
71 
78 template <typename Ex, typename... Args>
80 throw_exception(Args&&... args) {
81  detail::throw_exception_<Ex>(
82  detail::to_exception_arg_(static_cast<Args&&>(args))...);
83 }
84 
88 // clang-format off
89 template <typename Ex, typename... Args>
92  detail::terminate_with_<Ex>(
93  detail::to_exception_arg_(static_cast<Args&&>(args))...);
94 }
95 // clang-format on
96 
121 template <typename F, typename... A>
123  F&& f,
124  A&&... a) {
125  static_cast<F&&>(f)(static_cast<A&&>(a)...);
126  std::terminate();
127 }
128 
129 } // namespace folly
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN T && to_exception_arg_(T &&t)
Definition: Exception.h:52
auto f
std::unique_ptr< int > A
#define FOLLY_ALWAYS_INLINE
Definition: CPortability.h:151
FOLLY_NOINLINE FOLLY_COLD void terminate_with(Ex &&ex) noexcept
Definition: Exception.h:45
FOLLY_NOINLINE FOLLY_COLD void terminate_with_(Args &&...args) noexcept
Definition: Exception.h:65
FOLLY_NOINLINE FOLLY_COLD void throw_exception_(Args &&...args)
Definition: Exception.h:61
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
FOLLY_NOINLINE FOLLY_COLD void invoke_noreturn_cold(F &&f, A &&...a)
Definition: Exception.h:122
#define FOLLY_COLD
#define FOLLY_NOINLINE
Definition: CPortability.h:142
char a
const
Definition: upload.py:398
#define FOLLY_ATTR_VISIBILITY_HIDDEN
Definition: CPortability.h:160
FOLLY_NOINLINE FOLLY_COLD void throw_exception(Ex &&ex)
Definition: Exception.h:32