RDKit: Exceptions.h Source File

| 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//!
20 class RDKIT_RDGENERAL_EXPORT IndexErrorException : public std::runtime_error {
21 public:
22 IndexErrorException(int i)
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
IndexErrorException::what
const char * what() const noexcept override
Definition Exceptions.h:28
IndexErrorException::IndexErrorException
IndexErrorException(int i)
Definition Exceptions.h:22
IndexErrorException::~IndexErrorException
~IndexErrorException() noexcept override=default
IndexErrorException::index
int index() const
Definition Exceptions.h:26
KeyErrorException::key
std::string key() const
Definition Exceptions.h:62
KeyErrorException::what
const char * what() const noexcept override
Definition Exceptions.h:64
KeyErrorException::~KeyErrorException
~KeyErrorException() noexcept override=default
KeyErrorException::KeyErrorException
KeyErrorException(std::string key)
Definition Exceptions.h:58
ValueErrorException::ValueErrorException
ValueErrorException(const char *msg)
Definition Exceptions.h:44
ValueErrorException::~ValueErrorException
~ValueErrorException() noexcept override=default
ValueErrorException::what
const char * what() const noexcept override
Definition Exceptions.h:46
ValueErrorException::ValueErrorException
ValueErrorException(std::string i)
Definition Exceptions.h:42
export.h
RDKIT_RDGENERAL_EXPORT
#define RDKIT_RDGENERAL_EXPORT
Definition export.h:441