add stringVPrintf() and stringVAppendf()
[folly.git] / folly / wangle / WangleException.h
1 /*
2  * Copyright 2014 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 #include <string>
21
22 namespace folly { namespace wangle {
23
24 class WangleException : public std::exception {
25
26 public:
27
28   explicit WangleException(std::string message_arg)
29     : message(message_arg) {}
30
31   ~WangleException() throw(){}
32
33   virtual const char *what() const throw() {
34     return message.c_str();
35   }
36
37   bool operator==(const WangleException &other) const{
38     return other.message == this->message;
39   }
40
41   bool operator!=(const WangleException &other) const{
42     return !(*this == other);
43   }
44
45   protected:
46     std::string message;
47 };
48
49 class BrokenPromise : public WangleException {
50   public:
51     explicit BrokenPromise() :
52       WangleException("Broken promise") { }
53 };
54
55 class NoState : public WangleException {
56   public:
57     explicit NoState() : WangleException("No state") { }
58 };
59
60 class PromiseAlreadySatisfied : public WangleException {
61   public:
62     explicit PromiseAlreadySatisfied() :
63       WangleException("Promise already satisfied") { }
64 };
65
66 class FutureNotReady : public WangleException {
67   public:
68     explicit FutureNotReady() :
69       WangleException("Future not ready") { }
70 };
71
72 class FutureAlreadyRetrieved : public WangleException {
73   public:
74     explicit FutureAlreadyRetrieved () :
75       WangleException("Future already retrieved") { }
76 };
77
78 class UsingUninitializedTry : public WangleException {
79   public:
80     explicit UsingUninitializedTry() :
81       WangleException("Using unitialized try") { }
82 };
83
84 }}