libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
libdap::Error Class Reference

A class for error processing. More...

#include <Error.h>

Inheritance diagram for libdap::Error:
Inheritance graph

Public Member Functions

 Error ()
 
 Error (const Error &copy_from) noexcept
 
 Error (ErrorCode ec, std::string msg, std::string file="", int line=0)
 
 Error (std::string msg, std::string file="", int line=0)
 
ErrorCode get_error_code () const
 
std::string get_error_message () const
 
std::string get_file () const
 
int get_line () const
 
bool OK () const
 Is the Error object valid? More...
 
Erroroperator= (const Error &rhs)
 
bool parse (FILE *fp)
 Parse an Error object. More...
 
void print (FILE *out) const
 
void print (std::ostream &out) const
 
void set_error_code (ErrorCode ec=undefined_error)
 
void set_error_message (std::string msg="")
 
void set_file (std::string f)
 
void set_line (int l)
 
const char * what () const noexcept override
 The pointer is valid only for the lifetime of the Error instance. jhrg 9/22/20. More...
 

Protected Attributes

ErrorCode _error_code
 
std::string _error_message
 
std::string d_file
 
int d_line {}
 

Detailed Description

A class for error processing.

The Error class is used to transport error information from the server to the client within libdap. This class is also the base class for all the errors thrown by methods in the DAP, so catching Error will catch all DAP throws. Errors consist of an error code and a string. The code can be used to quickly distinguish between certain common errors while the string is used to convey information about the error to the user. The error code should never be displayed to the user.

This class is used on both clients and servers. The print() and parse() methods are used to send the object back and forth.

Note
A past version of this class supported the notion of an error correcting program (Tcl, Java, ...) that could be sent from the server to the client to help users correct the error and resubmit the request. This never worked well in practice and that feature of the class is deprecated.
Author
jhrg

Definition at line 93 of file Error.h.

Constructor & Destructor Documentation

◆ Error() [1/4]

libdap::Error::Error ( )
inline

Specializations of Error should use this to set the error code and message.

Definition at line 103 of file Error.h.

◆ Error() [2/4]

libdap::Error::Error ( ErrorCode  ec,
std::string  msg,
std::string  file = "",
int  line = 0 
)
inline

Create an instance with a specific code and message string. This ctor provides a way to to use any code and string you'd like. The code can be one of the standard codes or it may be specific to your server. Thus a client which can tell it's dealing with a specific type of server can use the code accordingly. In general, clients simply show the error message to users or write it to a log file.

Parameters
ecThe error code
msgThe error message string.
fileName of the source file (optional)
lineLine in the source file (optional)

Definition at line 117 of file Error.h.

◆ Error() [3/4]

libdap::Error::Error ( std::string  msg,
std::string  file = "",
int  line = 0 
)
inlineexplicit

Create an instance with a specific message. The error code is set to unknown_error.

Parameters
msgThe error message.
fileName of the source file (optional)
lineLine in the source file (optional)
See also
ErrorCode

Definition at line 129 of file Error.h.

◆ Error() [4/4]

libdap::Error::Error ( const Error copy_from)
inlinenoexcept

Definition at line 133 of file Error.h.

Member Function Documentation

◆ get_error_code()

ErrorCode libdap::Error::get_error_code ( ) const

Get the ErrorCode for this instance.

Definition at line 214 of file Error.cc.

◆ get_error_message()

string libdap::Error::get_error_message ( ) const

Return the current error message.

Definition at line 243 of file Error.cc.

◆ get_file()

std::string libdap::Error::get_file ( ) const
inline

Definition at line 150 of file Error.h.

◆ get_line()

int libdap::Error::get_line ( ) const
inline

Definition at line 152 of file Error.h.

◆ OK()

bool libdap::Error::OK ( ) const

Is the Error object valid?

Use this function to determine whether an Error object is valid. To be a valid, an Error object must either be: 1) empty or contain a message and a code.

Returns
TRUE if the object is valid, FALSE otherwise.

Definition at line 100 of file Error.cc.

◆ operator=()

Error & libdap::Error::operator= ( const Error rhs)

Definition at line 74 of file Error.cc.

◆ parse()

bool libdap::Error::parse ( FILE *  fp)

Parse an Error object.

Given an input stream (FILE *) fp, parse an Error object from stream. Values for fields of the Error object are parsed and this is set accordingly. This is how a client program receives an error object from a server.

Parameters
fpA valid file pointer to an input stream.
Returns
TRUE if no error was detected, FALSE otherwise.

Definition at line 123 of file Error.cc.

◆ print() [1/2]

void libdap::Error::print ( FILE *  out) const

Creates a printable representation of the Error object. It is suitable for framing, and also for printing and sending over a network.

The printed representation produced by this function can be parsed by the parse() member function. Thus parse and print form a symmetrical pair that can be used to send and receive an Error object over the network in a MIME document.

Parameters
outA pointer to the output stream on which the Error object is to be rendered.

Definition at line 165 of file Error.cc.

◆ print() [2/2]

void libdap::Error::print ( std::ostream &  out) const

Creates a printable representation of the Error object. It is suitable for framing, and also for printing and sending over a network.

The printed representation produced by this function can be parsed by the parse() member function. Thus parse and print form a symmetrical pair that can be used to send and receive an Error object over the network in a MIME document.

Parameters
strmA reference to the output stream on which the Error object is to be rendered.

Definition at line 194 of file Error.cc.

◆ set_error_code()

void libdap::Error::set_error_code ( ErrorCode  ec = undefined_error)

Set the ErrorCode. If the current error message has not been set, use ec to set the error message. The resulting error message string is the same as the ErrorCode name. If ec is not within the range of values for an OPeNDAP ErrorCode, the error message is left unchanged.

Parameters
ecThe new ErrorCode value.

Definition at line 227 of file Error.cc.

◆ set_error_message()

void libdap::Error::set_error_message ( std::string  msg = "")

Set the error message.

Definition at line 252 of file Error.cc.

◆ set_file()

void libdap::Error::set_file ( std::string  f)
inline

Definition at line 151 of file Error.h.

◆ set_line()

void libdap::Error::set_line ( int  l)
inline

Definition at line 153 of file Error.h.

◆ what()

const char * libdap::Error::what ( ) const
inlineoverridenoexcept

The pointer is valid only for the lifetime of the Error instance. jhrg 9/22/20.

Definition at line 156 of file Error.h.

Member Data Documentation

◆ _error_code

ErrorCode libdap::Error::_error_code
protected

Definition at line 96 of file Error.h.

◆ _error_message

std::string libdap::Error::_error_message
protected

Definition at line 97 of file Error.h.

◆ d_file

std::string libdap::Error::d_file
protected

Definition at line 98 of file Error.h.

◆ d_line

int libdap::Error::d_line {}
protected

Definition at line 99 of file Error.h.


The documentation for this class was generated from the following files: