GNU Octave  8.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-2023 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 (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.
64  void set_pos (octave_idx_type nd_arg, octave_idx_type dim_arg)
65  {
66  m_nd = nd_arg;
67  m_dim = dim_arg;
68 
69  update_message ();
70  }
71 
73  {
74  if (m_nd == 0)
75  {
76  m_nd = nd_arg;
77  m_dim = dim_arg;
78 
79  update_message ();
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 
88  update_message ();
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 OCTAVE_NORETURN extern OCTAVE_API void
136  octave_idx_type ext);
137 
138 OCTAVE_NORETURN extern OCTAVE_API void
139 err_invalid_index (double n, octave_idx_type nd = 0,
140  octave_idx_type dim = 0,
141  const std::string& var = "");
142 
143 OCTAVE_NORETURN extern OCTAVE_API void
145  octave_idx_type dim = 0,
146  const std::string& var = "");
147 
148 OCTAVE_NORETURN extern OCTAVE_API void
149 err_invalid_index (const std::string& idx, octave_idx_type nd = 0,
150  octave_idx_type dim = 0,
151  const std::string& var = "");
152 
153 OCTAVE_NORETURN extern OCTAVE_API void
154 err_invalid_resize (void);
155 
156 extern OCTAVE_API void
157 warn_singular_matrix (double rcond = 0.0);
158 
160 
161 #endif
OCTAVE_END_NAMESPACE(octave)
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
octave_idx_type m_nd
void set_pos(octave_idx_type nd_arg, octave_idx_type dim_arg)
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
~index_exception(void)=default
virtual void update_message(void)
octave_idx_type m_dim
void set_var(const std::string &var_arg="")
index_exception(const std::string &index, octave_idx_type nd=0, octave_idx_type dim=-1, const char *var="")
std::string m_index
virtual const char * err_id(void) const =0
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_NORETURN OCTAVE_API void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
OCTAVE_API void warn_singular_matrix(double rcond=0.0)
OCTAVE_NORETURN OCTAVE_API void err_nan_to_logical_conversion(void)
OCTAVE_NORETURN OCTAVE_API void err_index_out_of_range(int ndims, int dim, octave_idx_type idx, octave_idx_type ext, const dim_vector &dv)
OCTAVE_NORETURN OCTAVE_API void err_invalid_index(double n, octave_idx_type nd=0, octave_idx_type dim=0, const std::string &var="")
OCTAVE_NORETURN OCTAVE_API void err_invalid_resize(void)
OCTAVE_NORETURN OCTAVE_API void err_del_index_out_of_range(bool is1d, octave_idx_type iext, octave_idx_type ext)
OCTAVE_NORETURN OCTAVE_API void err_nan_to_character_conversion(void)
#define OCTAVE_API
Definition: main.in.cc:55
octave_idx_type n
Definition: mx-inlines.cc:753