casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
27 
28 #ifndef CASA_ARRAYERROR_2_H
29 #define CASA_ARRAYERROR_2_H
30 
31 //# Includes
32 #include <stdexcept>
33 #include <string>
34 
35 #include "IPosition.h"
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // <summary> The base class for all Array exception classes. </summary>
40 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
41 // </reviewed>
42 //
43 // ArrayError is the base class for all the Array-specific exception classes,
44 // i.e. if it is caught you will catch (through inheritance) all Array-specific
45 // exceptions. Note that (presently, anyway) the Array classes will throw
46 // a few non-Array exceptions.
47 // <srcblock>
48 // try {
49 // // Some lines, functions, ...
50 // } catch (ArrayError x) {
51 // // Array specific errors
52 // } catch (std::exception x) {
53 // // All other errors caught here.
54 // }
55 // </srcblock>
56 //
57 //# There are too many Array related error classes. Some should be deleted.
58 
59 class ArrayError : public std::runtime_error
60 {
61 public:
62  // Initialize with the message "ArrayError"
63  ArrayError();
64  // Initialize with the supplied message.
65  ArrayError(const char *m);
66  // Initialize with the supplied message.
67  ArrayError(const std::string& m);
68  ~ArrayError() noexcept;
69 };
70 
71 
72 // <summary> An error thrown when an index is out of range </summary>
73 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
74 // </reviewed>
75 //
76 // The ArrayIndexError class, which is derived from ArrayError, is intended
77 // to be thrown when an index is out-of-bounds. It contains within it
78 // the offending index, as well as the shape of the array which
79 // is being indexed. This should be multiply-derived from
80 // indexError<T> defined in Error.h.
82 {
83 public:
84  // Initialize with the message "ArrayIndexError".
86  // Initialize with the supplied message, the index and shape are null.
87  ArrayIndexError(const char *m);
88  // Initialize with the supplied message, the index and shape are null.
89  ArrayIndexError(const std::string &m);
90  // Initialize with a given out-of-bounds index, as well as the shape
91  // of the array and a supplied message.
93  const char *m="ArrayIndexError");
94  ~ArrayIndexError() noexcept;
95  // The out-of-bounds index.
96  IPosition index() const;
97  // The shape of the violated array.
98  IPosition shape() const;
99 private:
100  //# index, offset, length
102 };
103 
104 
105 // <summary> An error thrown when two arrays do not conform </summary>
106 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
107 // </reviewed>
108 //
109 // The ArrayConformanceError class is the base class for all errors thrown
110 // because two arrays are not conformant. See also the ArrayShapeError and
111 // ArrayNDimError classes which are derived from it. This error, or one derived
112 // from it, os normally thrown from a binary operation (arithmetic, logical,
113 // assignment, etc).
115 {
116 public:
117  // Initialize the message with "ArrayConformanceError".
119  // Initialize with a supplied message.
120  ArrayConformanceError(const char *m);
121  // Initialize with a supplied message.
122  ArrayConformanceError(const std::string& m);
123  ~ArrayConformanceError() noexcept;
124 };
125 
126 
127 // <summary> Thrown when two arrays have different dimensionality </summary>
128 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
129 // </reviewed>
130 //
131 // An ArrayNDimError is derived from ArrayConformanceError. It is thrown when
132 // two arrays are non-conformant by virtue of having different dimensionality.
133 // It holds within it the two dimensions.
135 {
136 public:
137  // Define the two (presumably different) messages and optionally
138  // supply a message.
139  ArrayNDimError(int dim1, int dim2, const char *m="ArrayNDimError");
140  ArrayNDimError(int dim1, int dim2, const std::string& m);
141  ~ArrayNDimError() noexcept;
142  // Return the stored dimensions. NB modifies arguments.
143  void ndims(int &dim1, int &dim2) const; // modifies arguments
144 private:
145  int r1, r2;
146 };
147 
148 
149 // <summary> An error thrown when two arrays have different shapes </summary>
150 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
151 // </reviewed>
152 //
153 // An ArrayShapeError is derived from ArrayConformanceError. It is thrown when
154 // two arrays are non-conformant by virtue of having different shapes.
155 // It holds within it the two different two shapes.
157 {
158 public:
159  // Define an ArrayShapeError with the two (presumably different) shapes
160  // and an optional supplied message.
161  ArrayShapeError(const IPosition &shape1, const IPosition &shape2,
162  const char *m="ArrayShapeError");
163  ~ArrayShapeError() noexcept;
164  // Get back the stored shapes. NB modifies arguments.
165  void shapes(IPosition &, IPosition &) const; // modifies arguments
166 private:
168 };
169 
170 
171 // <summary> An error thrown by an ArrayIterator </summary>
172 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
173 // </reviewed>
174 //
175 // An ArrayIteratorError is thrown by an array iterator or related class
176 // (e.g. VectorIterator).
178 {
179 public:
180  // Initialize with the message "ArrayIteratorError.
182  // Initialize with the supplied message
183  ArrayIteratorError(const char *m);
184  // Initialize with the supplied message
185  ArrayIteratorError(const std::string &m);
186  ~ArrayIteratorError() noexcept;
187 };
188 
189 
190 // <summary> An error thrown by an Slicer member function </summary>
191 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
192 // </reviewed>
193 //
194 // An ArraySlicerError is thrown by an Slicer member function.
196 {
197 public:
198  // Initialize with the message "Slicer error."
200  // Initialize with ArraySlicerError plus the supplied message
201  ArraySlicerError(const std::string &m);
202  ~ArraySlicerError() noexcept;
203 };
204 
205 
206 } //# NAMESPACE CASACORE - END
207 
208 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:118
~ArrayError() noexcept
The base class for all Array exception classes.
Definition: ArrayError.h:59
ArrayIndexError()
Initialize with the message &quot;ArrayIndexError&quot;.
ArraySlicerError()
Initialize with the message &quot;Slicer error.&quot;.
IPosition index() const
The out-of-bounds index.
void shapes(IPosition &, IPosition &) const
Get back the stored shapes.
ArrayError()
Initialize with the message &quot;ArrayError&quot;.
ArrayNDimError(int dim1, int dim2, const char *m="ArrayNDimError")
Define the two (presumably different) messages and optionally supply a message.
An error thrown when two arrays do not conform.
Definition: ArrayError.h:114
ArrayIteratorError()
Initialize with the message "ArrayIteratorError.
IPosition shape() const
The shape of the violated array.
An error thrown by an ArrayIterator.
Definition: ArrayError.h:177
An error thrown when an index is out of range.
Definition: ArrayError.h:81
An error thrown when two arrays have different shapes.
Definition: ArrayError.h:156
ArrayConformanceError()
Initialize the message with &quot;ArrayConformanceError&quot;.
void ndims(int &dim1, int &dim2) const
Return the stored dimensions.
An error thrown by an Slicer member function.
Definition: ArrayError.h:195
Thrown when two arrays have different dimensionality.
Definition: ArrayError.h:134
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...