ErrUt  1.1.0 (development version)
errorbase.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of ErrUt, a small collection of error handling
4  utilities.
5 
6  Copyright (c) 2008-2018 Jori Liesenborgs
7 
8  Contact: jori.liesenborgs@gmail.com
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  IN THE SOFTWARE.
27 
28 */
29 
34 #ifndef ERRUT_ERRORBASE_H
35 
36 #define ERRUT_ERRORBASE_H
37 
38 #include "errutconfig.h"
39 #include <string>
40 
41 namespace errut
42 {
43 
48 class ERRUT_IMPORTEXPORT ErrorBase
49 {
50 public:
52  ErrorBase() { m_objectName = std::string("Unnamed object"); }
53 
55  ErrorBase(const std::string &objName) { m_objectName = objName; }
56 
57  virtual ~ErrorBase() { }
58 
60  std::string getObjectName() const { return m_objectName; }
61 
63  std::string getErrorString() const { return m_errorString; }
64 protected:
66  void setErrorString(const std::string &str) const { m_errorString = str; }
67 private:
68  mutable std::string m_errorString;
69  std::string m_objectName;
70 };
71 
72 } // end namespace
73 
74 #endif // ERRUT_ERRORBASE_H
75 
Base class which allows an error message to be set.
Definition: errorbase.h:49
void setErrorString(const std::string &str) const
Derived classes can use this member function to store an error message.
Definition: errorbase.h:66
ErrorBase(const std::string &objName)
Creates an instance with the object name set to objName.
Definition: errorbase.h:55
ErrorBase()
Creates an instance without an explicit object name.
Definition: errorbase.h:52
std::string getObjectName() const
Returns the stored object name.
Definition: errorbase.h:60
std::string getErrorString() const
Returns the currently stored error message.
Definition: errorbase.h:63