Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
exceptions.hxx
1 /*
2  * Copyright 2021 Couchbase, 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 <boost/optional.hpp>
21 #include <couchbase/transactions/transaction_result.hxx>
22 
23 #include <stdexcept>
24 
25 namespace couchbase
26 {
27 namespace transactions
28 {
31  class transaction_context;
32 
33  enum external_exception {
34  UNKNOWN = 0,
35  ACTIVE_TRANSACTION_RECORD_ENTRY_NOT_FOUND,
36  ACTIVE_TRANSACTION_RECORD_FULL,
37  ACTIVE_TRANSACTION_RECORD_NOT_FOUND,
38  DOCUMENT_ALREADY_IN_TRANSACTION,
39  DOCUMENT_EXISTS_EXCEPTION,
40  DOCUMENT_NOT_FOUND_EXCEPTION,
41  NOT_SET,
42  FEATURE_NOT_AVAILABLE_EXCEPTION,
43  TRANSACTION_ABORTED_EXTERNALLY,
44  PREVIOUS_OPERATION_FAILED,
45  FORWARD_COMPATIBILITY_FAILURE
46  };
47 
53  class transaction_exception : public std::runtime_error
54  {
55  private:
56  const transaction_result result_;
57  external_exception cause_;
58 
59  public:
66  explicit transaction_exception(const std::runtime_error& cause, const transaction_context& context);
67 
74  {
75  return result_;
76  }
77 
83  external_exception cause() const
84  {
85  return cause_;
86  }
87  };
88 
94  class transaction_failed : public transaction_exception
95  {
96  public:
97  explicit transaction_failed(const std::runtime_error& cause, const transaction_context& context)
98  : transaction_exception(cause, context)
99  {
100  }
101  };
102 
111  {
112  public:
113  explicit transaction_expired(const std::runtime_error& cause, const transaction_context& context)
114  : transaction_exception(cause, context)
115  {
116  }
117  };
118 
127  {
128  public:
129  explicit transaction_commit_ambiguous(const std::runtime_error& cause, const transaction_context& context)
130  : transaction_exception(cause, context)
131  {
132  }
133  };
134 
135 } // namespace transactions
136 } // namespace couchbase
Definition: bucket.hxx:33
Transaction expired.
Definition: exceptions.hxx:111
const transaction_result & get_transaction_result() const
Internal state of transaction at time of exception.
Definition: exceptions.hxx:74
Results of a transaction.
Definition: transaction_result.hxx:32
external_exception cause() const
The cause of the exception.
Definition: exceptions.hxx:84
Transaction failed.
Definition: exceptions.hxx:95
Base class for all exceptions expected to be raised from a transaction.
Definition: exceptions.hxx:54
Transaction commit ambiguous.
Definition: exceptions.hxx:127
transaction_exception(const std::runtime_error &cause, const transaction_context &context)
Construct from underlying exception.