Mercurial > hg > octave-nkf
annotate liboctave/util/lo-array-gripes.cc @ 20827:e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
* lo-array-gripes.cc: Remove FIXME's related to buffer size. Shorten sprintf
buffers from 100 to 64 characters (still well more than 19 required).
Use 'const' decorator on constant value for clarity. Remove extra space
between variable and array bracket.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 12 Oct 2015 21:13:47 -0700 |
parents | dd6345fd8a97 |
children |
rev | line source |
---|---|
11135 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19605
diff
changeset
|
3 Copyright (C) 2003-2015 John W. Eaton |
11135 | 4 Copyright (C) 2009 VZLU Prague |
5 | |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 3 of the License, or (at your | |
11 option) any later version. | |
12 | |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with Octave; see the file COPYING. If not, see | |
20 <http://www.gnu.org/licenses/>. | |
21 | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
28 #include <string.h> |
11135 | 29 #include "lo-array-gripes.h" |
30 #include "lo-error.h" | |
31 | |
32 const char *error_id_nonconformant_args = "Octave:nonconformant-args"; | |
33 | |
34 const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds"; | |
35 | |
36 const char *error_id_invalid_index = "Octave:invalid-index"; | |
37 | |
19605
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
38 const char *warning_id_nearly_singular_matrix = "Octave:nearly-singular-matrix"; |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
39 |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
40 const char *warning_id_singular_matrix = "Octave:singular-matrix"; |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
41 |
11135 | 42 void |
43 gripe_nan_to_logical_conversion (void) | |
44 { | |
45 (*current_liboctave_error_handler) | |
46 ("invalid conversion from NaN to logical"); | |
47 } | |
48 | |
49 void | |
50 gripe_nan_to_character_conversion (void) | |
51 { | |
52 (*current_liboctave_error_handler) | |
53 ("invalid conversion from NaN to character"); | |
54 } | |
55 | |
56 void | |
57 gripe_nonconformant (const char *op, octave_idx_type op1_len, | |
58 octave_idx_type op2_len) | |
59 { | |
60 const char *err_id = error_id_nonconformant_args; | |
61 | |
62 (*current_liboctave_error_with_id_handler) | |
63 (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)", | |
64 op, op1_len, op2_len); | |
65 } | |
66 | |
67 void | |
68 gripe_nonconformant (const char *op, | |
69 octave_idx_type op1_nr, octave_idx_type op1_nc, | |
70 octave_idx_type op2_nr, octave_idx_type op2_nc) | |
71 { | |
72 const char *err_id = error_id_nonconformant_args; | |
73 | |
74 (*current_liboctave_error_with_id_handler) | |
75 (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)", | |
76 op, op1_nr, op1_nc, op2_nr, op2_nc); | |
77 } | |
78 | |
79 void | |
80 gripe_nonconformant (const char *op, const dim_vector& op1_dims, | |
81 const dim_vector& op2_dims) | |
82 { | |
83 const char *err_id = error_id_nonconformant_args; | |
84 | |
85 std::string op1_dims_str = op1_dims.str (); | |
86 std::string op2_dims_str = op2_dims.str (); | |
87 | |
88 (*current_liboctave_error_with_id_handler) | |
89 (err_id, "%s: nonconformant arguments (op1 is %s, op2 is %s)", | |
90 op, op1_dims_str.c_str (), op2_dims_str.c_str ()); | |
91 } | |
92 | |
93 void | |
94 gripe_del_index_out_of_range (bool is1d, octave_idx_type idx, | |
95 octave_idx_type ext) | |
96 { | |
97 const char *err_id = error_id_index_out_of_bounds; | |
98 | |
99 (*current_liboctave_error_with_id_handler) | |
100 (err_id, "A(%s) = []: index out of bounds; value %d out of bound %d", | |
101 is1d ? "I" : "..,I,..", idx, ext); | |
102 } | |
103 | |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
104 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
105 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
106 // Common procedures of base class index_exception, thrown whenever an |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
107 // object is indexed incorrectly, such as by an index that is out of |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
108 // range, negative, fractional, complex, or of a non-numeric type. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
109 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
110 const char * |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
111 index_exception::err (void) throw () |
11135 | 112 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
113 msg = access () + "; " + explain (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
114 return msg.c_str (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
115 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
116 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
117 // Show what was illegally accessed, e.g., "A(-1,_)", "A(0+1i)", "A(_,3)" |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
118 // Show how many indices come before/after the offending one, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
119 // e.g., (<error>), (<error>,_), or (_,<error>,...[x5]...) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
120 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
121 std::string |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
122 index_exception:: access (void) const |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
123 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
124 // FIXME: don't use a fixed size buffer! |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
125 const int buf_len = 300; |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
126 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
127 char output [buf_len]; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
128 char pre [buf_len]; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
129 char post [buf_len]; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
130 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
131 // dim == 0 if position not yet given, or |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
132 // <static_cast unsigned int>(-1) if explicitly shown to be unknown |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
133 // both are caught by this condition |
11135 | 134 |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
135 if (static_cast <unsigned int> (dim-1) > 100000) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
136 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
137 // No parentheses are given if the dimension is not known. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
138 pre[0] = post[0] = '\0'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
139 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
140 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
141 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
142 if (dim < 5) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
143 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
144 pre[0] = '('; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
145 octave_idx_type i; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
146 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
147 for (i = 1; i < dim; i++) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
148 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
149 pre[2*i-1] = '_'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
150 pre[2*i] = ','; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
151 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
152 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
153 pre[2*i-1] = '\0'; // i == min (1, dim) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
154 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
155 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
156 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
157 sprintf (pre, "(...[x%d]...", dim-1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
158 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
159 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
160 if (static_cast <unsigned int> (nd-dim) < 5) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
161 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
162 for (octave_idx_type i = 0; i < nd-dim; i++) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
163 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
164 post[2*i] = ','; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
165 post[2*i+1] = '_'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
166 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
167 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
168 if (nd >= dim) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
169 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
170 post[2*(nd-dim)] = ')'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
171 post[2*(nd-dim)+1] = '\0'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
172 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
173 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
174 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
175 sprintf (post, "...[x%d]...)", nd-dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
176 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
177 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
178 const char *v; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
179 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
180 if (var[0] == '\0' || var == "<unknown>") |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
181 v = "index "; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
182 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
183 v = var.c_str (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
184 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
185 snprintf (output, buf_len, "%s%s%s%s", v, pre, idx(), post); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
186 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
187 return output; |
11135 | 188 } |
189 | |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
190 class invalid_index : public index_exception |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
191 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
192 public: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
193 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
194 invalid_index (const char *value, octave_idx_type ndim, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
195 octave_idx_type dimen) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
196 : index_exception (value, ndim, dimen) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
197 { } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
198 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
199 const char* explain (void) const |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
200 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
201 #ifdef USE_64_BIT_IDX_T |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
202 return "subscripts must be either integers 1 to (2^63)-1 or logicals"; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
203 #else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
204 return "subscripts must be either integers 1 to (2^31)-1 or logicals"; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
205 #endif |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
206 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
207 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
208 // ID of error to throw |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
209 const char* id (void) const |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
210 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
211 return error_id_invalid_index; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
212 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
213 }; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
214 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
215 // Complain of an index that is: negative, fractional, or too big. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
216 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
217 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
218 gripe_invalid_index (const char *idx, octave_idx_type nd, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
219 octave_idx_type dim, const char * /* var */) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
220 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
221 invalid_index e (idx, nd, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
222 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
223 throw e; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
224 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
225 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
226 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
227 gripe_invalid_index (octave_idx_type n, octave_idx_type nd, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
228 octave_idx_type dim, const char *var) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
229 { |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
230 // Note: log10 (2^63) = 19 digits. Use 64 for ease of memory alignment. |
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
231 char buf[64]; |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
232 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
233 sprintf (buf, "%d", n+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
234 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
235 gripe_invalid_index (buf, nd, dim, var); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
236 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
237 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
238 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
239 gripe_invalid_index (double n, octave_idx_type nd, octave_idx_type dim, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
240 const char *var) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
241 { |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
242 char buf[64]; |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
243 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
244 sprintf (buf, "%g", n+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
245 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
246 gripe_invalid_index (buf, nd, dim, var); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
247 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
248 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
249 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
250 // Gripe and exception for read access beyond the bounds of an array. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
251 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
252 class out_of_range : public index_exception |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
253 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
254 public: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
255 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
256 out_of_range (const char *value, octave_idx_type nd_in,octave_idx_type dim_in) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
257 : index_exception (value, nd_in, dim_in), extent(0) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
258 { } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
259 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
260 const char* explain (void) const |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
261 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
262 static std::string expl; // should probably be member variable, but |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
263 // then explain() can't be const. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
264 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
265 if (nd >= size.length ()) // if not an index slice |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
266 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
267 if (var != "") |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
268 expl = "but " + var + " has size "; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
269 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
270 expl = "but object has size "; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
271 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
272 expl = expl + size.str ('x'); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
273 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
274 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
275 { |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
276 char buf[64]; |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
277 sprintf (buf, "%d", extent); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
278 expl = "out of bound " + std::string (buf); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
279 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
280 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
281 return expl.c_str (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
282 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
283 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
284 // ID of error to throw. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
285 const char* id (void) const |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
286 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
287 return (error_id_index_out_of_bounds); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
288 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
289 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
290 void set_size (const dim_vector& size_in) { size = size_in; } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
291 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
292 void set_extent (octave_idx_type ext) { extent = ext; } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
293 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
294 private: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
295 |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
296 dim_vector size; // dimension of object being accessed |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
297 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
298 octave_idx_type extent; // length of dimension being accessed |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
299 }; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
300 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
301 // Complain of an index that is out of range, but we don't know matrix size |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
302 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
303 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
304 octave_idx_type ext) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
305 { |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
306 char buf[64]; |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
307 sprintf (buf, "%d", idx); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
308 out_of_range e (buf, nd, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
309 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
310 e.set_extent (ext); |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
311 dim_vector d (1,1,1,1,1,1,1); // make explain() give extent not size |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
312 e.set_size (d); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
313 throw e; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
314 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
315 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
316 // Complain of an index that is out of range |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
317 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
318 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
319 octave_idx_type ext, const dim_vector& d) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
320 { |
20827
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20749
diff
changeset
|
321 char buf[64]; |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
322 sprintf (buf, "%d", idx); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
323 out_of_range e (buf, nd, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
324 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
325 e.set_extent (ext); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
326 e.set_size (d); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
327 throw e; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
328 } |
11135 | 329 |
330 void | |
331 gripe_invalid_resize (void) | |
332 { | |
333 (*current_liboctave_error_with_id_handler) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
334 ("Octave:invalid-resize", |
11590
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
335 "Invalid resizing operation or ambiguous assignment to an out-of-bounds array element"); |
11135 | 336 } |
337 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
338 void |
19605
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
339 gripe_singular_matrix (double rcond) |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
340 { |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
341 if (rcond == 0.0) |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
342 { |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
343 (*current_liboctave_warning_with_id_handler) |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
344 (warning_id_singular_matrix, |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
345 "matrix singular to machine precision"); |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
346 } |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
347 else |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
348 { |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
349 (*current_liboctave_warning_with_id_handler) |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
350 (warning_id_nearly_singular_matrix, |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
351 "matrix singular to machine precision, rcond = %g", rcond); |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
352 } |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
353 } |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
354 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19898
diff
changeset
|
355 /* Tests in test/index.tst */ |