All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
error.hpp
1 /*
2  * Copyright (c) 2020-2024, NVIDIA CORPORATION.
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 <rmm/detail/export.hpp>
20 
21 #include <stdexcept>
22 #include <string>
23 
24 namespace RMM_NAMESPACE {
25 
35 struct logic_error : public std::logic_error {
36  using std::logic_error::logic_error;
37 };
38 
45 struct cuda_error : public std::runtime_error {
46  using std::runtime_error::runtime_error;
47 };
48 
55 class bad_alloc : public std::bad_alloc {
56  public:
62  bad_alloc(const char* msg) : _what{std::string{std::bad_alloc::what()} + ": " + msg} {}
63 
69  bad_alloc(std::string const& msg) : bad_alloc{msg.c_str()} {}
70 
74  [[nodiscard]] const char* what() const noexcept override { return _what.c_str(); }
75 
76  private:
77  std::string _what;
78 };
79 
87 class out_of_memory : public bad_alloc {
88  public:
94  out_of_memory(const char* msg) : bad_alloc{std::string{"out_of_memory: "} + msg} {}
95 
101  out_of_memory(std::string const& msg) : out_of_memory{msg.c_str()} {}
102 };
103 
110 class out_of_range : public std::out_of_range {
111  using std::out_of_range::out_of_range;
112 };
113 
114 } // namespace RMM_NAMESPACE
Exception thrown when an RMM allocation fails.
Definition: error.hpp:55
const char * what() const noexcept override
The explanatory string.
Definition: error.hpp:74
bad_alloc(std::string const &msg)
Constructs a bad_alloc with the error message.
Definition: error.hpp:69
bad_alloc(const char *msg)
Constructs a bad_alloc with the error message.
Definition: error.hpp:62
Exception thrown when RMM runs out of memory.
Definition: error.hpp:87
out_of_memory(std::string const &msg)
Constructs an out_of_memory with the error message.
Definition: error.hpp:101
out_of_memory(const char *msg)
Constructs an out_of_memory with the error message.
Definition: error.hpp:94
Exception thrown when attempting to access outside of a defined range.
Definition: error.hpp:110
Exception thrown when a CUDA error is encountered.
Definition: error.hpp:45
Exception thrown when logical precondition is violated.
Definition: error.hpp:35