libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Error.h
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// (c) COPYRIGHT URI/MIT 1999,2000
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32// Interface for the Error class
33//
34// jhrg 4/23/96
35
36#ifndef _error_h
37#define _error_h
38
39#include <exception>
40#include <iostream>
41#include <string>
42
43#include <cstdio> // For FILE *
44#include <utility>
45
46using std::cout;
47using std::ostream;
48using std::string;
49
50namespace libdap {
51
57typedef int ErrorCode; // using standard errno+netCDF error codes from server
58
61#define undefined_error 1000
62#define unknown_error 1001
63#define internal_error 1002
64#define no_such_file 1003
65#define no_such_variable 1004
66#define malformed_expr 1005
67#define no_authorization 1006
68#define cannot_read_file 1007
69#define not_implemented 1008
70#define dummy_message 1009
72
91
92class Error : public std::exception {
93protected:
95 std::string _error_message;
96 std::string d_file;
97 int d_line = 0;
98
99public:
101 Error() : exception(), _error_code(undefined_error) {}
102
115 Error(ErrorCode ec, std::string msg, std::string file = "", int line = 0)
116 : exception(), _error_code(ec), _error_message(std::move(msg)), d_file(std::move(file)), d_line(line) {}
117
126 explicit Error(std::string msg, std::string file = "", int line = 0)
127 : exception(), _error_code(unknown_error), _error_message(std::move(msg)), d_file(std::move(file)),
128 d_line(line) {}
129
130 Error(const Error &copy_from) noexcept
131 : exception(), _error_code(copy_from._error_code), _error_message(copy_from._error_message) {}
132
133 ~Error() override = default;
134
135 Error &operator=(const Error &rhs);
136
137 bool OK() const;
138 bool parse(FILE *fp);
139 void print(FILE *out) const;
140 void print(std::ostream &out) const;
142 std::string get_error_message() const;
144 void set_error_message(std::string msg = "");
145
146 std::string get_file() const { return d_file; }
147 void set_file(std::string f) { d_file = std::move(f); }
148 int get_line() const { return d_line; }
149 void set_line(int l) { d_line = l; }
150
152 const char *what() const noexcept override { return _error_message.c_str(); }
153};
154
155} // namespace libdap
156
157#endif // _error_h
#define unknown_error
Unknown error (the default code) (HTTP 400)
Definition Error.h:62
#define undefined_error
Undefined error code, an empty Error object was built.
Definition Error.h:61
ErrorCode _error_code
Definition Error.h:94
Error & operator=(const Error &rhs)
Definition Error.cc:63
Error(ErrorCode ec, std::string msg, std::string file="", int line=0)
Definition Error.h:115
void set_error_message(std::string msg="")
Definition Error.cc:219
int get_line() const
Definition Error.h:148
void set_error_code(ErrorCode ec=undefined_error)
Definition Error.cc:200
std::string get_file() const
Definition Error.h:146
void print(FILE *out) const
Definition Error.cc:144
void set_line(int l)
Definition Error.h:149
~Error() override=default
std::string _error_message
Definition Error.h:95
void set_file(std::string f)
Definition Error.h:147
const char * what() const noexcept override
The pointer is valid only for the lifetime of the Error instance. jhrg 9/22/20.
Definition Error.h:152
ErrorCode get_error_code() const
Definition Error.cc:189
std::string get_error_message() const
Definition Error.cc:212
Error(std::string msg, std::string file="", int line=0)
Definition Error.h:126
bool parse(FILE *fp)
Parse an Error object.
Definition Error.cc:106
std::string d_file
Definition Error.h:96
bool OK() const
Is the Error object valid?
Definition Error.cc:87
Error(const Error &copy_from) noexcept
Definition Error.h:130
int d_line
Definition Error.h:97
top level DAP object to house generic methods
Definition AISConnect.cc:30
int ErrorCode
An enumerated type for common errors.
Definition Error.h:57