RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Exceptions.h
Go to the documentation of this file.
1//
2// Copyright (c) 2003-2005 greg Landrum and Rational Discovery LLC
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10#include <RDGeneral/export.h>
11#ifndef _RD_EXCEPTIONS_H
12#define _RD_EXCEPTIONS_H
13#include <stdexcept>
14#include <string>
15#include <utility>
16
17//! \brief Class to allow us to throw an \c IndexError from C++ and have
18//! it make it back to Python
19//!
20class RDKIT_RDGENERAL_EXPORT IndexErrorException : public std::runtime_error {
21 public:
23 : std::runtime_error("IndexErrorException"),
24 _idx(i),
25 _msg("Index Error: " + std::to_string(_idx)) {}
26 int index() const { return _idx; }
27
28 const char *what() const noexcept override { return _msg.c_str(); }
29
30 ~IndexErrorException() noexcept override = default;
31
32 private:
33 int _idx;
34 std::string _msg;
35};
36
37//! \brief Class to allow us to throw a \c ValueError from C++ and have
38//! it make it back to Python
39//!
40class RDKIT_RDGENERAL_EXPORT ValueErrorException : public std::runtime_error {
41 public:
42 ValueErrorException(std::string i)
43 : std::runtime_error("ValueErrorException"), _value(std::move(i)) {}
44 ValueErrorException(const char *msg)
45 : std::runtime_error("ValueErrorException"), _value(msg) {}
46 const char *what() const noexcept override { return _value.c_str(); }
47 ~ValueErrorException() noexcept override = default;
48
49 private:
50 std::string _value;
51};
52
53//! \brief Class to allow us to throw a \c KeyError from C++ and have
54//! it make it back to Python
55//!
56class RDKIT_RDGENERAL_EXPORT KeyErrorException : public std::runtime_error {
57 public:
58 KeyErrorException(std::string key)
59 : std::runtime_error("KeyErrorException"),
60 _key(key),
61 _msg("Key Error: " + key) {}
62 std::string key() const { return _key; }
63
64 const char *what() const noexcept override { return _msg.c_str(); }
65
66 ~KeyErrorException() noexcept override = default;
67
68 private:
69 std::string _key;
70 std::string _msg;
71};
72
73#endif
Class to allow us to throw an IndexError from C++ and have it make it back to Python.
Definition Exceptions.h:20
const char * what() const noexcept override
Definition Exceptions.h:28
IndexErrorException(int i)
Definition Exceptions.h:22
~IndexErrorException() noexcept override=default
int index() const
Definition Exceptions.h:26
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
Definition Exceptions.h:56
std::string key() const
Definition Exceptions.h:62
const char * what() const noexcept override
Definition Exceptions.h:64
~KeyErrorException() noexcept override=default
KeyErrorException(std::string key)
Definition Exceptions.h:58
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
Definition Exceptions.h:40
ValueErrorException(const char *msg)
Definition Exceptions.h:44
~ValueErrorException() noexcept override=default
const char * what() const noexcept override
Definition Exceptions.h:46
ValueErrorException(std::string i)
Definition Exceptions.h:42
#define RDKIT_RDGENERAL_EXPORT
Definition export.h:409