libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
Error.h
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 <iostream>
40 #include <string>
41 #include <exception>
42 
43 #include <cstdio> // For FILE *
44 
45 using std::cout;
46 using std::string;
47 using std::ostream;
48 
49 namespace libdap
50 {
51 
57 typedef 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
71 
72 
73 
92 class Error : public std::exception
93 {
94 protected:
95  ErrorCode _error_code;
96  std::string _error_message;
97 
98  std::string d_file;
99  int d_line;
100 
101 public:
102  Error(ErrorCode ec, std::string msg, std::string file = "", int line = 0);
103  Error(std::string msg, std::string file = "", int line = 0);
104  Error();
105 
106  Error(const Error &copy_from);
107 
108  virtual ~Error() throw();
109 
110  Error &operator=(const Error &rhs);
111 
112  bool OK() const;
113  bool parse(FILE *fp);
114  void print(FILE *out) const;
115  void print(std::ostream &out) const;
116  ErrorCode get_error_code() const;
117  std::string get_error_message() const;
118  void set_error_code(ErrorCode ec = undefined_error);
119  void set_error_message(std::string msg = "");
120 
121  std::string get_file() const { return d_file; }
122  void set_file(std::string f) { d_file = f; }
123  int get_line() const { return d_line; }
124  void set_line(int l) { d_line = l; }
125 
127  virtual const char* what() const throw() {
128  return _error_message.c_str();
129  }
130 };
131 
132 } // namespace libdap
133 
134 #endif // _error_h
void set_error_message(std::string msg="")
Definition: Error.cc:287
bool parse(FILE *fp)
Parse an Error object.
Definition: Error.cc:158
void set_error_code(ErrorCode ec=undefined_error)
Definition: Error.cc:262
top level DAP object to house generic methods
Definition: AISConnect.cc:30
bool OK() const
Is the Error object valid?
Definition: Error.cc:135
ErrorCode get_error_code() const
Definition: Error.cc:249
std::string get_error_message() const
Definition: Error.cc:278
int ErrorCode
An enumerated type for common errors.
Definition: Error.h:57
void print(FILE *out) const
Definition: Error.cc:200
virtual const char * what() const
The pointer is valid only for the lifetime of the Error instance. jhrg 9/22/20.
Definition: Error.h:127
A class for error processing.
Definition: Error.h:92