libdap Updated for version 3.20.5
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
45using std::cout;
46using std::string;
47using std::ostream;
48
49namespace libdap
50{
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
92class Error : public std::exception
93{
94protected:
95 ErrorCode _error_code;
96 std::string _error_message;
97
98public:
99 Error(ErrorCode ec, std::string msg);
100 Error(std::string msg);
101 Error();
102
103 Error(const Error &copy_from);
104
105 virtual ~Error() throw();
106
107 Error &operator=(const Error &rhs);
108
109 bool OK() const;
110 bool parse(FILE *fp);
111 void print(FILE *out) const;
112 void print(std::ostream &out) const;
114 std::string get_error_message() const;
115 void set_error_code(ErrorCode ec = undefined_error);
116 void set_error_message(std::string msg = "");
117
118 virtual const char* what() const throw() {
119 return get_error_message().c_str();
120 }
121};
122
123} // namespace libdap
124
125#endif // _error_h
A class for error processing.
Definition Error.h:93
void set_error_message(std::string msg="")
Definition Error.cc:284
void set_error_code(ErrorCode ec=undefined_error)
Definition Error.cc:259
void print(FILE *out) const
Definition Error.cc:197
ErrorCode get_error_code() const
Definition Error.cc:246
std::string get_error_message() const
Definition Error.cc:275
bool parse(FILE *fp)
Parse an Error object.
Definition Error.cc:155
bool OK() const
Is the Error object valid?
Definition Error.cc:132
top level DAP object to house generic methods
int ErrorCode
An enumerated type for common errors.
Definition Error.h:57