Electroneum
error.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018, The Monero Project
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without modification, are
5 // permitted provided that the following conditions are met:
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this list of
8 // conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 // of conditions and the following disclaimer in the documentation and/or other
12 // materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its contributors may be
15 // used to endorse or promote products derived from this software without specific
16 // prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
19 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "error.h"
28 
29 #include <string>
30 
31 namespace
32 {
33  struct category final : std::error_category
34  {
35  virtual const char* name() const noexcept override final
36  {
37  return "common_category()";
38  }
39 
40  virtual std::string message(int value) const override final
41  {
42  switch (common_error(value))
43  {
45  return make_error_code(std::errc::invalid_argument).message();
47  return "expect<T> was given an error value of zero";
48  default:
49  break;
50  }
51  return "Unknown basic_category() value";
52  }
53 
54  virtual std::error_condition default_error_condition(int value) const noexcept override final
55  {
56  // maps specific errors to generic `std::errc` cases.
57  switch (common_error(value))
58  {
61  return std::errc::invalid_argument;
62  default:
63  break;
64  }
65  return std::error_condition{value, *this};
66  }
67  };
68 }
69 
71 {
72  static const category instance{};
73  return instance;
74 }
75 
::std::string string
Definition: gtest-port.h:1097
std::error_code make_error_code(::common_error value) noexcept
Definition: error.h:41
common_error
Definition: error.h:32
const char * name
A function argument is invalid.
std::error_category const & common_category() noexcept
Definition: error.cpp:70
std::string message("Message requiring signing")
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
Default std::error_code given to expect<T>
std::error_category const & error_category() noexcept
Definition: error.cpp:87