GNU Octave  9.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-2024 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 
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 
44 class OCTAVE_EXCEPTION_API index_exception : public execution_exception
45 {
46 public:
47 
48  index_exception () = delete;
49 
50  index_exception (const std::string& index, octave_idx_type nd = 0,
51  octave_idx_type dim = -1, const char *var = "")
52  : m_index (index), m_nd (nd), m_dim (dim), m_var (var)
53  {
54  set_message (expression ());
55  }
56 
57  OCTAVE_DEFAULT_COPY_MOVE (index_exception)
58 
59  ~index_exception () = default;
60 
61  // ID of error to throw.
62  virtual const char * err_id () const = 0;
63 
64  // By default, update message to show the erroneous index expression.
65  virtual void update_message () { set_message (expression ()); }
66 
67  // Position of error: dimension in error, and number of dimensions.
68  void set_pos (octave_idx_type nd_arg, octave_idx_type dim_arg)
69  {
70  m_nd = nd_arg;
71  m_dim = dim_arg;
72 
73  update_message ();
74  }
75 
77  {
78  if (m_nd == 0)
79  {
80  m_nd = nd_arg;
81  m_dim = dim_arg;
82 
83  update_message ();
84  }
85  }
86 
87  // Name of variable being indexed. eye(2)(1,1) gives "<unknown>".
88  void set_var (const std::string& var_arg = "")
89  {
90  m_var = var_arg;
91 
92  update_message ();
93  }
94 
95  // Return a newly allocated copy of the index_exception object.
96  virtual index_exception * dup () = 0;
97 
98 private:
99 
100  // Value of invalid index.
101  std::string m_index;
102 
103 protected:
104 
105  // Show what's wrong, e.g., A(-1,_), A(0+1i).
106  OCTAVE_API std::string expression () const;
107 
108  // Number of dimensions of indexed object.
110 
111  // Dimension number in which invalid index occurred.
113 
114  // Name of variable being indexed.
115  std::string m_var;
116 };
117 
118 OCTAVE_NORETURN extern OCTAVE_API void
120 
121 OCTAVE_NORETURN extern OCTAVE_API void
123 
124 OCTAVE_NORETURN extern OCTAVE_API void
125 err_nonconformant (const char *op, octave_idx_type op1_len,
126  octave_idx_type op2_len);
127 
128 OCTAVE_NORETURN extern OCTAVE_API void
129 err_nonconformant (const char *op,
130  octave_idx_type op1_nr, octave_idx_type op1_nc,
131  octave_idx_type op2_nr, octave_idx_type op2_nc);
132 
133 OCTAVE_NORETURN extern OCTAVE_API void
134 err_nonconformant (const char *op,
135  const dim_vector& op1_dims, const dim_vector& op2_dims);
136 
137 OCTAVE_NORETURN extern OCTAVE_API void
138 err_index_out_of_range (int ndims, int dim, octave_idx_type idx,
139  octave_idx_type ext, const dim_vector& dv);
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
162 
163 extern OCTAVE_API void
164 warn_singular_matrix (double rcond = 0.0);
165 
166 OCTAVE_END_NAMESPACE(octave)
167 
168 #endif
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
index_exception()=delete
octave_idx_type m_nd
void set_pos(octave_idx_type nd_arg, octave_idx_type dim_arg)
~index_exception()=default
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
virtual const char * err_id() const =0
octave_idx_type m_dim
void set_var(const std::string &var_arg="")
virtual index_exception * dup()=0
index_exception(const std::string &index, octave_idx_type nd=0, octave_idx_type dim=-1, const char *var="")
virtual void update_message()
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_NORETURN void err_del_index_out_of_range(bool is1d, octave_idx_type iext, octave_idx_type ext)
OCTAVE_NORETURN void err_nan_to_logical_conversion()
void warn_singular_matrix(double rcond=0.0)
OCTAVE_NORETURN void err_index_out_of_range(int ndims, int dim, octave_idx_type idx, octave_idx_type ext, const dim_vector &dv)
OCTAVE_NORETURN void err_invalid_resize()
OCTAVE_NORETURN void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
OCTAVE_NORETURN void err_nan_to_character_conversion()
OCTAVE_NORETURN void err_invalid_index(double n, octave_idx_type nd=0, octave_idx_type dim=0, const std::string &var="")
#define OCTAVE_API
Definition: main.cc:55
octave_idx_type n
Definition: mx-inlines.cc:761