folly::FutureException inherits from std::logic_error, like std::future_error; become...
[folly.git] / folly / futures / FutureException.h
1 /*
2  * Copyright 2016 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 namespace folly {
23
24 class FutureException : public std::logic_error {
25  public:
26   using std::logic_error::logic_error;
27 };
28
29 class BrokenPromise : public FutureException {
30  public:
31   explicit BrokenPromise(const std::string& type)
32       : FutureException("Broken promise for type name `" + type + '`') {}
33
34   explicit BrokenPromise(const char* type) : BrokenPromise(std::string(type)) {}
35 };
36
37 class NoState : public FutureException {
38  public:
39   NoState() : FutureException("No state") {}
40 };
41
42 class PromiseAlreadySatisfied : public FutureException {
43  public:
44   PromiseAlreadySatisfied() : FutureException("Promise already satisfied") {}
45 };
46
47 class FutureNotReady : public FutureException {
48  public:
49   FutureNotReady() : FutureException("Future not ready") {}
50 };
51
52 class FutureAlreadyRetrieved : public FutureException {
53  public:
54   FutureAlreadyRetrieved() : FutureException("Future already retrieved") {}
55 };
56
57 class FutureCancellation : public FutureException {
58  public:
59   FutureCancellation() : FutureException("Future was cancelled") {}
60 };
61
62 class TimedOut : public FutureException {
63  public:
64   TimedOut() : FutureException("Timed out") {}
65 };
66
67 class PredicateDoesNotObtain : public FutureException {
68  public:
69   PredicateDoesNotObtain() : FutureException("Predicate does not obtain") {}
70 };
71
72 }