GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
lo-array-errwarn.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2016-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_lo_array_errwarn_h)
27#define octave_lo_array_errwarn_h 1
28
29#include "octave-config.h"
30
31#include "dim-vector.h"
32#include "quit.h"
33
34namespace octave
35{
36 // Exception thrown by err_invalid_index
37 // This is thrown when the invalid index is detected, at which point nd and dim
38 // are usually not known. It is caught at the place they are known, where a
39 // new err_invalid_index is called.
40 //
41 // Typically, this should be caught after any call to
42 // octave_value_list::index_vector()
43
45 {
46 public:
47
48 index_exception (const std::string& index, octave_idx_type nd = 0,
49 octave_idx_type dim = -1, const char *var = "")
50 : m_index (index), m_nd (nd), m_dim (dim), m_var (var)
51 {
52 set_message (expression ());
53 }
54
55 ~index_exception (void) = default;
56
57 // ID of error to throw.
58 virtual const char * err_id (void) const = 0;
59
60 // By default, update message to show the erroneous index expression.
61 virtual void update_message (void) { set_message (expression ()); }
62
63 // Position of error: dimension in error, and number of dimensions.
65 {
66 m_nd = nd_arg;
67 m_dim = dim_arg;
68
70 }
71
73 {
74 if (m_nd == 0)
75 {
76 m_nd = nd_arg;
77 m_dim = dim_arg;
78
80 }
81 }
82
83 // Name of variable being indexed. eye(2)(1,1) gives "<unknown>".
84 void set_var (const std::string& var_arg = "")
85 {
86 m_var = var_arg;
87
89 }
90
91 private:
92
93 // Value of invalid index.
94 std::string m_index;
95
96 protected:
97
98 // Show what's wrong, e.g., A(-1,_), A(0+1i).
99 OCTAVE_API std::string expression (void) const;
100
101 // Number of dimensions of indexed object.
103
104 // Dimension number in which invalid index occurred.
106
107 // Name of variable being indexed.
108 std::string m_var;
109 };
110
111 OCTAVE_NORETURN extern OCTAVE_API void
113
114 OCTAVE_NORETURN extern OCTAVE_API void
116
117 OCTAVE_NORETURN extern OCTAVE_API void
118 err_nonconformant (const char *op, octave_idx_type op1_len,
119 octave_idx_type op2_len);
120
121 OCTAVE_NORETURN extern OCTAVE_API void
122 err_nonconformant (const char *op,
123 octave_idx_type op1_nr, octave_idx_type op1_nc,
124 octave_idx_type op2_nr, octave_idx_type op2_nc);
125
126 OCTAVE_NORETURN extern OCTAVE_API void
127 err_nonconformant (const char *op,
128 const dim_vector& op1_dims, const dim_vector& op2_dims);
129
130 OCTAVE_NORETURN extern OCTAVE_API void
131 err_index_out_of_range (int ndims, int dim, octave_idx_type idx,
132 octave_idx_type ext, const dim_vector& dv);
133
134#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
135 OCTAVE_DEPRECATED (6, "use err_index_out_of_range (int, int, octave_idx_type, octave_idx_type, const dim_vector&) instead")
136 OCTAVE_NORETURN extern OCTAVE_API void
137 err_index_out_of_range (int ndims, int dim, octave_idx_type idx,
138 octave_idx_type ext);
139#endif
140
141 OCTAVE_NORETURN extern OCTAVE_API void
143 octave_idx_type ext);
144
145 OCTAVE_NORETURN extern OCTAVE_API void
146 err_invalid_index (double n, octave_idx_type nd = 0,
147 octave_idx_type dim = 0,
148 const std::string& var = "");
149
150 OCTAVE_NORETURN extern OCTAVE_API void
152 octave_idx_type dim = 0,
153 const std::string& var = "");
154
155 OCTAVE_NORETURN extern OCTAVE_API void
156 err_invalid_index (const std::string& idx, octave_idx_type nd = 0,
157 octave_idx_type dim = 0,
158 const std::string& var = "");
159
160 OCTAVE_NORETURN extern OCTAVE_API void
161 err_invalid_resize (void);
162
163 extern OCTAVE_API void
164 warn_singular_matrix (double rcond = 0.0);
165}
166
167#endif
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
virtual const char * err_id(void) const =0
virtual void update_message(void)
~index_exception(void)=default
void set_pos(octave_idx_type nd_arg, octave_idx_type dim_arg)
OCTAVE_API std::string expression(void) const
index_exception(const std::string &index, octave_idx_type nd=0, octave_idx_type dim=-1, const char *var="")
void set_var(const std::string &var_arg="")
#define OCTAVE_API
Definition: main.in.cc:55
static OCTAVE_NORETURN void err_index_out_of_range(void)
Definition: idx-vector.cc:52
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
void err_del_index_out_of_range(bool is1d, octave_idx_type idx, octave_idx_type ext)
void err_nan_to_logical_conversion(void)
void err_invalid_resize(void)
void warn_singular_matrix(double rcond)
void err_nan_to_character_conversion(void)
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)