casacore
Loading...
Searching...
No Matches
ArrayError.h
Go to the documentation of this file.
1// # ArrayError.h: Exception classes thrown by Array and related classes/functions
2// # Copyright (C) 1993,1994,1995,1999,2000
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_ARRAYERROR_2_H
27#define CASA_ARRAYERROR_2_H
28
29// # Includes
30#include <stdexcept>
31#include <string>
32
33#include "IPosition.h"
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary> The base class for all Array exception classes. </summary>
38// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
39// </reviewed>
40//
41// ArrayError is the base class for all the Array-specific exception classes,
42// i.e. if it is caught you will catch (through inheritance) all Array-specific
43// exceptions. Note that (presently, anyway) the Array classes will throw
44// a few non-Array exceptions.
45// <srcblock>
46// try {
47// // Some lines, functions, ...
48// } catch (ArrayError x) {
49// // Array specific errors
50// } catch (std::exception x) {
51// // All other errors caught here.
52// }
53// </srcblock>
54//
55// # There are too many Array related error classes. Some should be deleted.
56
57class ArrayError : public std::runtime_error {
58 public:
59 // Initialize with the message "ArrayError"
61 // Initialize with the supplied message.
62 ArrayError(const char *m);
63 // Initialize with the supplied message.
64 ArrayError(const std::string &m);
65 ~ArrayError() noexcept;
66};
67
68// <summary> An error thrown when an index is out of range </summary>
69// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
70// </reviewed>
71//
72// The ArrayIndexError class, which is derived from ArrayError, is intended
73// to be thrown when an index is out-of-bounds. It contains within it
74// the offending index, as well as the shape of the array which
75// is being indexed. This should be multiply-derived from
76// indexError<T> defined in Error.h.
78 public:
79 // Initialize with the message "ArrayIndexError".
81 // Initialize with the supplied message, the index and shape are null.
82 ArrayIndexError(const char *m);
83 // Initialize with the supplied message, the index and shape are null.
84 ArrayIndexError(const std::string &m);
85 // Initialize with a given out-of-bounds index, as well as the shape
86 // of the array and a supplied message.
88 const char *m = "ArrayIndexError");
89 ~ArrayIndexError() noexcept;
90 // The out-of-bounds index.
92 // The shape of the violated array.
94
95 private:
96 // # index, offset, length
98};
99
100// <summary> An error thrown when two arrays do not conform </summary>
101// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
102// </reviewed>
103//
104// The ArrayConformanceError class is the base class for all errors thrown
105// because two arrays are not conformant. See also the ArrayShapeError and
106// ArrayNDimError classes which are derived from it. This error, or one derived
107// from it, os normally thrown from a binary operation (arithmetic, logical,
108// assignment, etc).
110 public:
111 // Initialize the message with "ArrayConformanceError".
113 // Initialize with a supplied message.
114 ArrayConformanceError(const char *m);
115 // Initialize with a supplied message.
116 ArrayConformanceError(const std::string &m);
118};
119
120// <summary> Thrown when two arrays have different dimensionality </summary>
121// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
122// </reviewed>
123//
124// An ArrayNDimError is derived from ArrayConformanceError. It is thrown when
125// two arrays are non-conformant by virtue of having different dimensionality.
126// It holds within it the two dimensions.
128 public:
129 // Define the two (presumably different) messages and optionally
130 // supply a message.
131 ArrayNDimError(int dim1, int dim2, const char *m = "ArrayNDimError");
132 ArrayNDimError(int dim1, int dim2, const std::string &m);
133 ~ArrayNDimError() noexcept;
134 // Return the stored dimensions. NB modifies arguments.
135 void ndims(int &dim1, int &dim2) const; // modifies arguments
136 private:
137 int r1, r2;
138};
139
140// <summary> An error thrown when two arrays have different shapes </summary>
141// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
142// </reviewed>
143//
144// An ArrayShapeError is derived from ArrayConformanceError. It is thrown when
145// two arrays are non-conformant by virtue of having different shapes.
146// It holds within it the two different two shapes.
148 public:
149 // Define an ArrayShapeError with the two (presumably different) shapes
150 // and an optional supplied message.
151 ArrayShapeError(const IPosition &shape1, const IPosition &shape2,
152 const char *m = "ArrayShapeError");
154 // Get back the stored shapes. NB modifies arguments.
155 void shapes(IPosition &, IPosition &) const; // modifies arguments
156 private:
158};
159
160// <summary> An error thrown by an ArrayIterator </summary>
161// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
162// </reviewed>
163//
164// An ArrayIteratorError is thrown by an array iterator or related class
165// (e.g. VectorIterator).
167 public:
168 // Initialize with the message "ArrayIteratorError.
170 // Initialize with the supplied message
171 ArrayIteratorError(const char *m);
172 // Initialize with the supplied message
173 ArrayIteratorError(const std::string &m);
175};
176
177// <summary> An error thrown by an Slicer member function </summary>
178// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
179// </reviewed>
180//
181// An ArraySlicerError is thrown by an Slicer member function.
183 public:
184 // Initialize with the message "Slicer error."
186 // Initialize with ArraySlicerError plus the supplied message
187 ArraySlicerError(const std::string &m);
189};
190
191} // namespace casacore
192
193#endif
ArrayConformanceError()
Initialize the message with "ArrayConformanceError".
ArrayConformanceError(const char *m)
Initialize with a supplied message.
ArrayConformanceError(const std::string &m)
Initialize with a supplied message.
ArrayError(const std::string &m)
Initialize with the supplied message.
ArrayError(const char *m)
Initialize with the supplied message.
ArrayError()
Initialize with the message "ArrayError".
~ArrayError() noexcept
ArrayIndexError(const char *m)
Initialize with the supplied message, the index and shape are null.
ArrayIndexError(const IPosition &index, const IPosition &shape, const char *m="ArrayIndexError")
Initialize with a given out-of-bounds index, as well as the shape of the array and a supplied message...
IPosition index() const
The out-of-bounds index.
ArrayIndexError()
Initialize with the message "ArrayIndexError".
IPosition shape() const
The shape of the violated array.
ArrayIndexError(const std::string &m)
Initialize with the supplied message, the index and shape are null.
ArrayIteratorError()
Initialize with the message "ArrayIteratorError.
ArrayIteratorError(const char *m)
Initialize with the supplied message.
ArrayIteratorError(const std::string &m)
Initialize with the supplied message.
ArrayNDimError(int dim1, int dim2, const char *m="ArrayNDimError")
Define the two (presumably different) messages and optionally supply a message.
void ndims(int &dim1, int &dim2) const
Return the stored dimensions.
ArrayNDimError(int dim1, int dim2, const std::string &m)
void shapes(IPosition &, IPosition &) const
Get back the stored shapes.
ArrayShapeError(const IPosition &shape1, const IPosition &shape2, const char *m="ArrayShapeError")
Define an ArrayShapeError with the two (presumably different) shapes and an optional supplied message...
ArraySlicerError()
Initialize with the message "Slicer error.".
ArraySlicerError(const std::string &m)
Initialize with ArraySlicerError plus the supplied message.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28