give folly future's exceptions default visibility
[folly.git] / folly / futures / FutureException.h
1 /*
2  * Copyright 2017 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 <stdexcept>
20 #include <string>
21
22 #include <folly/CPortability.h>
23
24 namespace folly {
25
26 class FOLLY_EXPORT FutureException : public std::logic_error {
27  public:
28   using std::logic_error::logic_error;
29 };
30
31 class FOLLY_EXPORT BrokenPromise : public FutureException {
32  public:
33   explicit BrokenPromise(const std::string& type)
34       : FutureException("Broken promise for type name `" + type + '`') {}
35
36   explicit BrokenPromise(const char* type) : BrokenPromise(std::string(type)) {}
37 };
38
39 class FOLLY_EXPORT NoState : public FutureException {
40  public:
41   NoState() : FutureException("No state") {}
42 };
43
44 [[noreturn]] void throwNoState();
45
46 class FOLLY_EXPORT PromiseAlreadySatisfied : public FutureException {
47  public:
48   PromiseAlreadySatisfied() : FutureException("Promise already satisfied") {}
49 };
50
51 [[noreturn]] void throwPromiseAlreadySatisfied();
52
53 class FOLLY_EXPORT FutureNotReady : public FutureException {
54  public:
55   FutureNotReady() : FutureException("Future not ready") {}
56 };
57
58 [[noreturn]] void throwFutureNotReady();
59
60 class FOLLY_EXPORT FutureAlreadyRetrieved : public FutureException {
61  public:
62   FutureAlreadyRetrieved() : FutureException("Future already retrieved") {}
63 };
64
65 [[noreturn]] void throwFutureAlreadyRetrieved();
66
67 class FOLLY_EXPORT FutureCancellation : public FutureException {
68  public:
69   FutureCancellation() : FutureException("Future was cancelled") {}
70 };
71
72 class FOLLY_EXPORT TimedOut : public FutureException {
73  public:
74   TimedOut() : FutureException("Timed out") {}
75 };
76
77 [[noreturn]] void throwTimedOut();
78
79 class FOLLY_EXPORT PredicateDoesNotObtain : public FutureException {
80  public:
81   PredicateDoesNotObtain() : FutureException("Predicate does not obtain") {}
82 };
83
84 [[noreturn]] void throwPredicateDoesNotObtain();
85
86 struct FOLLY_EXPORT NoFutureInSplitter : FutureException {
87   NoFutureInSplitter() : FutureException("No Future in this FutureSplitter") {}
88 };
89
90 [[noreturn]] void throwNoFutureInSplitter();
91 }