GNU Octave  6.2.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-2021 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 
34 namespace 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.
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  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 OCTAVE_API extern void
113 
114  OCTAVE_NORETURN OCTAVE_API extern void
116 
117  OCTAVE_NORETURN OCTAVE_API extern void
118  err_nonconformant (const char *op, octave_idx_type op1_len,
119  octave_idx_type op2_len);
120 
121  OCTAVE_NORETURN OCTAVE_API extern 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 OCTAVE_API extern void
127  err_nonconformant (const char *op,
128  const dim_vector& op1_dims, const dim_vector& op2_dims);
129 
130  OCTAVE_NORETURN OCTAVE_API extern 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_DEPRECATED (6, "use err_index_out_of_range (int, int, octave_idx_type, octave_idx_type, const dim_vector&) instead")
135  OCTAVE_NORETURN OCTAVE_API extern void
136  err_index_out_of_range (int ndims, int dim, octave_idx_type idx,
137  octave_idx_type ext);
138 
139  OCTAVE_NORETURN OCTAVE_API extern void
141  octave_idx_type ext);
142 
143  OCTAVE_NORETURN OCTAVE_API extern void
144  err_invalid_index (double n, octave_idx_type nd = 0,
145  octave_idx_type dim = 0,
146  const std::string& var = "");
147 
148  OCTAVE_NORETURN OCTAVE_API extern void
150  octave_idx_type dim = 0,
151  const std::string& var = "");
152 
153  OCTAVE_NORETURN OCTAVE_API extern void
154  err_invalid_index (const std::string& idx, octave_idx_type nd = 0,
155  octave_idx_type dim = 0,
156  const std::string& var = "");
157 
158  OCTAVE_NORETURN OCTAVE_API extern void
159  err_invalid_resize (void);
160 
161  OCTAVE_API extern void
162  warn_singular_matrix (double rcond = 0.0);
163 }
164 
165 #endif
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
virtual void update_message(void)
~index_exception(void)=default
void set_pos(octave_idx_type nd_arg, octave_idx_type dim_arg)
std::string expression(void) const
virtual const char * err_id(void) const =0
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="")
octave_idx_type n
Definition: mx-inlines.cc:753
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 err_index_out_of_range(int nd, int dim, octave_idx_type idx, octave_idx_type ext, const dim_vector &dv)
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)