bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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// Forward declaration of BESInfo since BESInfo.h
42// already includes BESError.h
43class BESInfo;
44
45#define BES_INTERNAL_ERROR 1
46
47// BES_INTERNAL_FATAL_ERROR will cause the bes listener to exit()
48// while the others (BES_INTERNAL_ERROR, ...) won't.
49// But, see the new option BES.ExitOnInternalError, which causes the
50// BES to exit on an InternalError.
51#define BES_INTERNAL_FATAL_ERROR 2
52
53#define BES_SYNTAX_USER_ERROR 3
54#define BES_FORBIDDEN_ERROR 4
55#define BES_NOT_FOUND_ERROR 5
56
57// I added this for the timeout feature. jhrg 12/28/15
58#define BES_TIMEOUT_ERROR 6
59
60// A BES_HTTP_ERROR is thrown when a request to another service fails.
61#define BES_HTTP_ERROR 7
62
66class BESError : public std::exception, public BESObj {
67private:
68 std::string _msg{"UNDEFINED"};
69 unsigned int _type{0};
70 std::string _file;
71 unsigned int _line{0};
72
73public:
74 BESError() = default;
75
87 BESError(std::string msg, unsigned int type, std::string file, unsigned int line) :
88 _msg(std::move(msg)), _type(type), _file(std::move(file)), _line(line) {}
89
94 BESError(const BESError &src) noexcept
95 : exception(), _msg(src._msg), _type(src._type), _file(src._file), _line(src._line) {}
96
97 ~BESError() override = default;
98
102 BESError &operator=(const BESError &rhs) = delete;
103
108 void set_message(const std::string &msg) {
109 _msg = msg;
110 }
111
116 virtual void add_my_error_details_to(BESInfo & /*bes_info*/) const {
117 // Most BESError types have simple semantics.
118 // Adding their pertinent information to the BESInfo object
119 // is handled by interrogating the BESError base class methods.
120 // This includes the basic details: FILE, LINE, and message.
121 // Others error types, like HttpError, are more complex in both state and
122 // API. In order for these types of error to be ingested into a BESInfo
123 // object to be serialized to the BESClient this method is called.
124 // Thus, in many cases the child of BESError does not override this
125 // method, but more complex type like HttpError take advantage of this.
126 }
127
132 std::string get_message() const {
133 return _msg;
134 }
135
140 std::string get_file() const {
141 return _file;
142 }
143
148 unsigned int get_line() const {
149 return _line;
150 }
151
152 // Return the message, file and line. Over load this for special messages, etc.
153 virtual std::string get_verbose_message() const;
154
164 void set_bes_error_type(unsigned int type) {
165 _type = type;
166 }
167
174 unsigned int get_bes_error_type() const {
175 return _type;
176 }
177
178 // The pointer is valid only for the lifetime of the BESError instance. jhrg 3/29/22
179
184 const char *what() const noexcept override {
185 return _msg.c_str();
186 }
187
192 void dump(std::ostream &strm) const override;
193
194 virtual std::string error_name() const { return "BESError"; }
195
196};
197
198#endif // BESError_h_
Base exception class for the BES with basic string message.
Definition BESError.h:66
BESError & operator=(const BESError &rhs)=delete
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:87
unsigned int get_line() const
get the line number where the exception was thrown
Definition BESError.h:148
BESError(const BESError &src) noexcept
Definition BESError.h:94
unsigned int get_bes_error_type() const
Return the return code for this error class.
Definition BESError.h:174
void dump(std::ostream &strm) const override
Displays debug information about this object.
Definition BESError.cc:59
const char * what() const noexcept override
Return a brief message about the exception.
Definition BESError.h:184
std::string get_file() const
get the file name where the exception was thrown
Definition BESError.h:140
std::string get_message() const
get the error message for this exception
Definition BESError.h:132
void set_bes_error_type(unsigned int type)
Set the return code for this particular error class.
Definition BESError.h:164
void set_message(const std::string &msg)
set the error message for this exception
Definition BESError.h:108
virtual void add_my_error_details_to(BESInfo &) const
Definition BESError.h:116
informational response object
Definition BESInfo.h:63
top level BES object to house generic methods
Definition BESObj.h:54