XVector
xvec_error.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2026 XCENA 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 
22 #pragma once
23 
24 #ifdef __cplusplus
25 
26 #include <stdexcept>
27 #include <string>
28 
29 #include "xvector/xvec_types.h"
30 
31 namespace xvec
32 {
33 
39 class Error : public std::runtime_error
40 {
41 public:
42  Error(xvecStatus status, const std::string& message)
43  : std::runtime_error(message),
44  status_(status)
45  {
46  }
47 
48  xvecStatus status() const noexcept
49  {
50  return status_;
51  }
52 
53 private:
54  xvecStatus status_;
55 };
56 
57 namespace detail
58 {
59 
60 inline void checkStatus(xvecStatus status, const char* function)
61 {
62  if (status != XVEC_SUCCESS)
63  {
64  throw Error(status, std::string(function) + " failed (status=" +
65  std::to_string(static_cast<int>(status)) + ")");
66  }
67 }
68 
69 } // namespace detail
70 
71 } // namespace xvec
72 
73 #endif // __cplusplus
Exception type for XVECTOR C API errors.
Definition: xvec_error.hpp:40
xvecStatus status() const noexcept
Definition: xvec_error.hpp:48
Error(xvecStatus status, const std::string &message)
Definition: xvec_error.hpp:42
void checkStatus(xvecStatus status, const char *function)
Definition: xvec_error.hpp:60
Core types, enums, and structures for the XVector library.
xvecStatus
Status codes returned by XVector API functions.
Definition: xvec_types.h:133
@ XVEC_SUCCESS
Operation completed successfully.
Definition: xvec_types.h:135