bes  Updated for version 3.20.13
BESError.h
1 // BESError.h
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #ifndef BESError_h_
34 #define BESError_h_ 1
35 
36 #include <string>
37 #include <stdexcept>
38 
39 #include "BESObj.h"
40 
41 #define BES_INTERNAL_ERROR 1
42 
43 // BES_INTERNAL_FATAL_ERROR will cause the bes listener to exit()
44 // while the others (BES_INTERNAL_ERROR, ...) won't.
45 // But, see the new option BES.ExitOnInternalError, which causes the
46 // BES to exit on an InternalError.
47 #define BES_INTERNAL_FATAL_ERROR 2
48 
49 #define BES_SYNTAX_USER_ERROR 3
50 #define BES_FORBIDDEN_ERROR 4
51 #define BES_NOT_FOUND_ERROR 5
52 
53 // I added this for the timeout feature. jhrg 12/28/15
54 #define BES_TIMEOUT_ERROR 6
55 
59 class BESError: public std::exception, public BESObj {
60 private:
61  std::string _msg {"UNDEFINED"};
62  unsigned int _type {0};
63  std::string _file;
64  unsigned int _line {0};
65 
66  BESError() = default;
67 
68 public:
80  BESError(std::string msg, unsigned int type, std::string file, unsigned int line) :
81  _msg(std::move(msg)), _type(type), _file(std::move(file)), _line(line)
82  { }
83 
88  BESError(const BESError &src) noexcept
89  : exception(), _msg(src._msg), _type(src._type), _file(src._file), _line(src._line) { }
90 
91  ~BESError() override = default;
92 
96  BESError &operator=(const BESError &rhs) = delete;
97 
102  void set_message(const std::string &msg)
103  {
104  _msg = msg;
105  }
106 
111  std::string get_message() const
112  {
113  return _msg;
114  }
115 
120  std::string get_file() const
121  {
122  return _file;
123  }
124 
129  unsigned int get_line() const
130  {
131  return _line;
132  }
133 
134  // Return the message, file and line. Over load this for special messages, etc.
135  virtual std::string get_verbose_message() const;
136 
146  void set_bes_error_type(unsigned int type)
147  {
148  _type = type;
149  }
150 
157  unsigned int get_bes_error_type() const
158  {
159  return _type;
160  }
161 
162  // The pointer is valid only for the lifetime of the BESError instance. jhrg 3/29/22
163 
168  const char* what() const noexcept override {
169  return _msg.c_str();
170  }
171 
176  void dump(std::ostream &strm) const override;
177 };
178 
179 #endif // BESError_h_
Base exception class for the BES with basic string message.
Definition: BESError.h:59
BESError(std::string msg, unsigned int type, std::string file, unsigned int line)
constructor that takes message, type of error, source file the error originated and the line number i...
Definition: BESError.h:80
unsigned int get_line() const
get the line number where the exception was thrown
Definition: BESError.h:129
BESError(const BESError &src) noexcept
Definition: BESError.h:88
unsigned int get_bes_error_type() const
Return the return code for this error class.
Definition: BESError.h:157
const char * what() const noexcept override
Return a brief message about the exception.
Definition: BESError.h:168
void dump(std::ostream &strm) const override
Displays debug information about this object.
Definition: BESError.cc:59
std::string get_file() const
get the file name where the exception was thrown
Definition: BESError.h:120
std::string get_message() const
get the error message for this exception
Definition: BESError.h:111
BESError & operator=(const BESError &rhs)=delete
void set_bes_error_type(unsigned int type)
Set the return code for this particular error class.
Definition: BESError.h:146
void set_message(const std::string &msg)
set the error message for this exception
Definition: BESError.h:102
top level BES object to house generic methods
Definition: BESObj.h:54