RDKit
Open-source cheminformatics and machine learning.
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 
16 //! \brief Class to allow us to throw an \c IndexError from C++ and have
17 //! it make it back to Python
18 //!
19 class IndexErrorException : public std::runtime_error {
20  public:
22  : std::runtime_error("IndexErrorException"), _idx(i){};
23  int index() const { return _idx; };
24  ~IndexErrorException() throw(){};
25 
26  private:
27  int _idx;
28 };
29 
30 //! \brief Class to allow us to throw a \c ValueError from C++ and have
31 //! it make it back to Python
32 //!
33 class ValueErrorException : public std::runtime_error {
34  public:
35  ValueErrorException(const std::string &i)
36  : std::runtime_error("ValueErrorException"), _value(i){};
37  ValueErrorException(const char *msg)
38  : std::runtime_error("ValueErrorException"), _value(msg){};
39  std::string message() const { return _value; };
40  ~ValueErrorException() throw(){};
41 
42  private:
43  std::string _value;
44 };
45 
46 //! \brief Class to allow us to throw a \c KeyError from C++ and have
47 //! it make it back to Python
48 //!
49 class KeyErrorException : public std::runtime_error {
50  public:
51  KeyErrorException(std::string key)
52  : std::runtime_error("KeyErrorException"), _key(key){};
53  std::string key() const { return _key; };
54  ~KeyErrorException() throw(){};
55 
56  private:
57  std::string _key;
58 };
59 
60 #endif
int index() const
Definition: Exceptions.h:23
KeyErrorException(std::string key)
Definition: Exceptions.h:51
STL namespace.
std::string message() const
Definition: Exceptions.h:39
std::string key() const
Definition: Exceptions.h:53
Class to allow us to throw an IndexError from C++ and have it make it back to Python.
Definition: Exceptions.h:19
ValueErrorException(const std::string &i)
Definition: Exceptions.h:35
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
Definition: Exceptions.h:33
IndexErrorException(int i)
Definition: Exceptions.h:21
ValueErrorException(const char *msg)
Definition: Exceptions.h:37
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
Definition: Exceptions.h:49