File indexing completed on 2024-04-14 03:42:33

0001 //#     Filename:   SpatialException.h
0002 //#
0003 //#     Author:     Peter Z Kunszt based on John Doug Reynolds'code
0004 //#
0005 //#     Date:       March 1998
0006 //#
0007 //#     SPDX-FileCopyrightText: 2000 Peter Z. Kunszt Alex S. Szalay, Aniruddha R. Thakar
0008 //#                     The Johns Hopkins University
0009 //#
0010 //#     Modification History:
0011 //#
0012 //#     Oct 18, 2001 : Dennis C. Dinge -- Replaced ValVec with std::vector
0013 //#
0014 
0015 #ifndef _SpatialException_h
0016 #define _SpatialException_h
0017 
0018 #include "SpatialGeneral.h"
0019 
0020 /** HTM SpatialIndex Exception base class
0021     This is the base class for all Science Archive exceptions.  It may
0022     be used as a generic exception, but programmers are encouraged to
0023     use the more specific derived classes.  Note that all Spatial
0024     exceptions are also Standard Library exceptions by
0025     inheritance.
0026 */
0027 
0028 class LINKAGE SpatialException
0029 {
0030   public:
0031     /** Default and explicit constructor.
0032             The default constructor
0033             supplies a generic message indicating the exception type.  The
0034             explicit constructor sets the message to a copy of the provided
0035             string.  This behavior is shared by all derived classes.
0036         */
0037 
0038     SpatialException(const char *what = nullptr, int defIndex = 1) throw();
0039 
0040     /** Standard constructor.
0041             The message is assembled from copies of
0042             the two component strings.  The first indicates where in the
0043             program the exception was thrown, and the second indicates why.
0044             The null pointer is used to select standard components according
0045             to the type of the exception.  This behavior is shared by all
0046             derived classes.
0047         */
0048     SpatialException(const char *context, const char *because, int defIndex = 1) throw();
0049 
0050     /// Copy constructor.
0051     SpatialException(const SpatialException &) throw();
0052 
0053     /// Assignment operator.
0054     SpatialException &operator=(const SpatialException &) throw();
0055 
0056     /// Destructor.
0057     virtual ~SpatialException() throw();
0058 
0059     /// Returns the message as set during construction.
0060     virtual const char *what() const throw();
0061 
0062     /// return string length also for null strings
0063     int slen(const char *) const;
0064 
0065     /// deallocate string
0066     void clear();
0067 
0068     /// default error string
0069     static const char *defaultstr[];
0070 
0071   protected:
0072     /// error string to assemble
0073     char *str_;
0074 };
0075 
0076 /** SpatialException thrown by unimplemented functions.
0077     This Exception should be thrown wherever
0078     important functionality has been left temporarily unimplemented.
0079     Typically this exception will apply to an entire function.
0080 */
0081 
0082 class LINKAGE SpatialUnimplemented : public SpatialException
0083 {
0084   public:
0085     /// Default and explicit constructors.
0086     SpatialUnimplemented(const char *what = nullptr) throw();
0087 
0088     /// Standard constructor.
0089     SpatialUnimplemented(const char *context, const char *because) throw();
0090 
0091     /// Copy constructor.
0092     SpatialUnimplemented(const SpatialUnimplemented &) throw();
0093 };
0094 
0095 /** SpatialException thrown on operational failure.
0096     This Exception should be thrown when an operation
0097     fails unexpectedly.  A special constructor is provided for
0098     assembling the message from the typical components: program
0099     context, operation name, resource name, and explanation.  As usual,
0100     any component may be left out by specifying the null pointer.
0101 */
0102 
0103 class LINKAGE SpatialFailure : public SpatialException
0104 {
0105   public:
0106     /// Default and explicit constructors.
0107     SpatialFailure(const char *what = nullptr) throw();
0108 
0109     /// Standard constructor.
0110     SpatialFailure(const char *context, const char *because) throw();
0111 
0112     /// Special constructor.
0113     SpatialFailure(const char *context, const char *operation, const char *resource, const char *because = nullptr) throw();
0114 
0115     /// Copy constructor.
0116     SpatialFailure(const SpatialFailure &) throw();
0117 };
0118 
0119 /** SpatialException thrown on violation of array bounds.
0120     This Exception should be thrown on detection of an
0121     attempt to access elements beyond the boundaries of an array.  A
0122     special constructor is provided for assembling the message from the
0123     typical components: program context, array name, violated boundary,
0124     and violating index.
0125 */
0126 
0127 class LINKAGE SpatialBoundsError : public SpatialException
0128 {
0129   public:
0130     /// Default and explicit constructors.
0131     SpatialBoundsError(const char *what = nullptr) throw();
0132 
0133     /** Standard constructor.
0134             If limit and index are -1, both are
0135             considered unknown.  Note that the upper limit of a zero-offset
0136             array is not the same as the number of elements.
0137         */
0138     SpatialBoundsError(const char *context, const char *array, int32 limit = -1, int32 index = -1) throw();
0139 
0140     /// Copy constructor.
0141     SpatialBoundsError(const SpatialBoundsError &) throw();
0142 };
0143 
0144 /** SpatialException thrown on violation of interface protocols.
0145     This Exception should be thrown when a program,
0146     class, or function interface requirement is breached.
0147     Specifically, this includes improper usage and invalid arguments.
0148     For the latter, a special constructor is provided for assembling
0149     the message from the typical components: program context, argument
0150     name, and explanation.
0151 */
0152 
0153 class LINKAGE SpatialInterfaceError : public SpatialException
0154 {
0155   public:
0156     /// Default and explicit constructors.
0157     SpatialInterfaceError(const char *what = nullptr) throw();
0158 
0159     /// Standard constructor.
0160     SpatialInterfaceError(const char *context, const char *because) throw();
0161 
0162     /// Special constructor.
0163     SpatialInterfaceError(const char *context, const char *argument, const char *because) throw();
0164 
0165     /// Copy constructor.
0166     SpatialInterfaceError(const SpatialInterfaceError &) throw();
0167 };
0168 
0169 #endif /* _SpatialException_h */