Error.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// (c) COPYRIGHT URI/MIT 1999,2000
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
// Interface for the Error class
//
// jhrg 4/23/96
#ifndef _error_h
#define _error_h
#include <exception>
#include <iostream>
#include <string>
#include <cstdio> // For FILE *
#include <utility>
using std::cout;
using std::ostream;
using std::string;
namespace libdap {
typedef int ErrorCode; // using standard errno+netCDF error codes from server
#define undefined_error 1000
#define unknown_error 1001
#define internal_error 1002
#define no_such_file 1003
#define no_such_variable 1004
#define malformed_expr 1005
#define no_authorization 1006
#define cannot_read_file 1007
#define not_implemented 1008
#define dummy_message 1009
class Error : public std::exception {
protected:
ErrorCode _error_code;
std::string _error_message;
std::string d_file;
int d_line = 0;
public:
Error() : exception(), _error_code(undefined_error) {}
Error(ErrorCode ec, std::string msg, std::string file = "", int line = 0)
: exception(), _error_code(ec), _error_message(std::move(msg)), d_file(std::move(file)), d_line(line) {}
explicit Error(std::string msg, std::string file = "", int line = 0)
: exception(), _error_code(unknown_error), _error_message(std::move(msg)), d_file(std::move(file)),
d_line(line) {}
Error(const Error &copy_from) noexcept
: exception(), _error_code(copy_from._error_code), _error_message(copy_from._error_message) {}
~Error() override = default;
Error &operator=(const Error &rhs);
bool OK() const;
bool parse(FILE *fp);
void print(FILE *out) const;
void print(std::ostream &out) const;
ErrorCode get_error_code() const;
std::string get_error_message() const;
void set_error_code(ErrorCode ec = undefined_error);
void set_error_message(std::string msg = "");
std::string get_file() const { return d_file; }
void set_file(std::string f) { d_file = std::move(f); }
int get_line() const { return d_line; }
void set_line(int l) { d_line = l; }
const char *what() const noexcept override { return _error_message.c_str(); }
};
} // namespace libdap
#endif // _error_h
libdap::Error
A class for error processing.
Definition Error.h:92
libdap::Error::Error
Error()
Definition Error.h:101
libdap::Error::Error
Error(ErrorCode ec, std::string msg, std::string file="", int line=0)
Definition Error.h:115
libdap::Error::set_error_message
void set_error_message(std::string msg="")
Definition Error.cc:219
libdap::Error::set_error_code
void set_error_code(ErrorCode ec=undefined_error)
Definition Error.cc:200
libdap::Error::print
void print(FILE *out) const
Definition Error.cc:144
libdap::Error::what
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
libdap::Error::get_error_code
ErrorCode get_error_code() const
Definition Error.cc:189
libdap::Error::get_error_message
std::string get_error_message() const
Definition Error.cc:212
libdap::Error::Error
Error(std::string msg, std::string file="", int line=0)
Definition Error.h:126
libdap::Error::parse
bool parse(FILE *fp)
Parse an Error object.
Definition Error.cc:106
libdap::Error::OK
bool OK() const
Is the Error object valid?
Definition Error.cc:87
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:35
libdap::ErrorCode
int ErrorCode
An enumerated type for common errors.
Definition Error.h:57