Mercurial > octave
annotate liboctave/util/lo-array-gripes.cc @ 20652:7a8096f8df5d
more cleanup of indexing exceptions
* data.cc (index_error): New function.
(Fnth_element, F__accumarray_sum__, __accumdim_sum__): Use it.
* lo-array-gripes.h, lo-array-gripes.cc (index_exception::message):
Rename from index_exception::err. Return std::string instead of const
char *. Change all uses.
(index_exception::expression): Rename from index_exception::access.
(index_exception::index_exception, invalid_index::invalid_index,
out_of_range::out_of_range): Accept const string& instead of const
char *. Change all uses.
(invalid_index::details): Rename from invalid_index::explain. Return
std::string instead of const char *. Change all uses.
(invalid_index::err_idx): Rename from invalid_index::id. Return
std::string instead of const char *. Change all uses.
(gripe_invalid_index): Accept const std::string& argument instead of
const char *.
(index_exception::~index_exception): Don't declare with "throw ()".
(index_exception::details): Rename from index_exception::explain. Return
std::string instead of const char *. Change all uses.
(index_exception::err_idx): Rename from index_exception::id. Return
std::string instead of const char *. Change all uses.
(index_exception::idx): Return std::string instead of const char *.
Change all uses.
(index_exception::err_id): Rename from index_exception::id.
(index_exception::msg): Delete member variable.
(index_expression::expression): Rename from index_expression::access.
Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Oct 2015 23:43:46 -0400 |
parents | c1d94e5cd5ea |
children | c16947991354 |
rev | line source |
---|---|
11135 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19408
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 | |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
28 #include <cstring> |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
29 |
11135 | 30 #include "lo-array-gripes.h" |
31 #include "lo-error.h" | |
32 | |
33 const char *error_id_nonconformant_args = "Octave:nonconformant-args"; | |
34 | |
35 const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds"; | |
36 | |
37 const char *error_id_invalid_index = "Octave:invalid-index"; | |
38 | |
19408
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
39 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
|
40 |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
41 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
|
42 |
11135 | 43 void |
44 gripe_nan_to_logical_conversion (void) | |
45 { | |
46 (*current_liboctave_error_handler) | |
47 ("invalid conversion from NaN to logical"); | |
48 } | |
49 | |
50 void | |
51 gripe_nan_to_character_conversion (void) | |
52 { | |
53 (*current_liboctave_error_handler) | |
54 ("invalid conversion from NaN to character"); | |
55 } | |
56 | |
57 void | |
58 gripe_nonconformant (const char *op, octave_idx_type op1_len, | |
59 octave_idx_type op2_len) | |
60 { | |
61 const char *err_id = error_id_nonconformant_args; | |
62 | |
63 (*current_liboctave_error_with_id_handler) | |
64 (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)", | |
65 op, op1_len, op2_len); | |
66 } | |
67 | |
68 void | |
69 gripe_nonconformant (const char *op, | |
70 octave_idx_type op1_nr, octave_idx_type op1_nc, | |
71 octave_idx_type op2_nr, octave_idx_type op2_nc) | |
72 { | |
73 const char *err_id = error_id_nonconformant_args; | |
74 | |
75 (*current_liboctave_error_with_id_handler) | |
76 (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)", | |
77 op, op1_nr, op1_nc, op2_nr, op2_nc); | |
78 } | |
79 | |
80 void | |
81 gripe_nonconformant (const char *op, const dim_vector& op1_dims, | |
82 const dim_vector& op2_dims) | |
83 { | |
84 const char *err_id = error_id_nonconformant_args; | |
85 | |
86 std::string op1_dims_str = op1_dims.str (); | |
87 std::string op2_dims_str = op2_dims.str (); | |
88 | |
89 (*current_liboctave_error_with_id_handler) | |
90 (err_id, "%s: nonconformant arguments (op1 is %s, op2 is %s)", | |
91 op, op1_dims_str.c_str (), op2_dims_str.c_str ()); | |
92 } | |
93 | |
94 void | |
95 gripe_del_index_out_of_range (bool is1d, octave_idx_type idx, | |
96 octave_idx_type ext) | |
97 { | |
98 const char *err_id = error_id_index_out_of_bounds; | |
99 | |
100 (*current_liboctave_error_with_id_handler) | |
101 (err_id, "A(%s) = []: index out of bounds; value %d out of bound %d", | |
102 is1d ? "I" : "..,I,..", idx, ext); | |
103 } | |
104 | |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
105 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
106 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
107 // 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:
19697
diff
changeset
|
108 // 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:
19697
diff
changeset
|
109 // 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:
19697
diff
changeset
|
110 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
111 std::string |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
112 index_exception::message (void) const |
11135 | 113 { |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
114 std::string msg = expression () + "; " + details (); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
115 return msg.c_str (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
116 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
117 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
118 // Show the expression that caused the error, e.g., "A(-1,_)", |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
119 // "A(0+1i)", "A(_,3)". Show how many indices come before/after the |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
120 // offending one, e.g., (<error>), (<error>,_), or (_,<error>,...[x5]...) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
121 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
122 std::string |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
123 index_exception::expression (void) const |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
124 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
125 // FIXME: don't use a fixed size buffer! |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
126 const int buf_len = 300; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
127 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
128 char output [buf_len]; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
129 char pre [buf_len]; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
130 char post [buf_len]; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
131 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
132 // 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:
19697
diff
changeset
|
133 // <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:
19697
diff
changeset
|
134 // both are caught by this condition |
11135 | 135 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
136 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:
19697
diff
changeset
|
137 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
138 // 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:
19697
diff
changeset
|
139 pre[0] = post[0] = '\0'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
140 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
141 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
142 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
143 if (dim < 5) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
144 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
145 pre[0] = '('; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
146 octave_idx_type i; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
147 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
148 for (i = 1; i < dim; i++) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
149 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
150 pre[2*i-1] = '_'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
151 pre[2*i] = ','; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
152 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
153 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
154 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:
19697
diff
changeset
|
155 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
156 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
157 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
158 sprintf (pre, "(...[x%d]...", dim-1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
159 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
160 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
161 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:
19697
diff
changeset
|
162 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
163 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:
19697
diff
changeset
|
164 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
165 post[2*i] = ','; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
166 post[2*i+1] = '_'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
167 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
168 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
169 if (nd >= dim) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
170 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
171 post[2*(nd-dim)] = ')'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
172 post[2*(nd-dim)+1] = '\0'; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
173 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
174 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
175 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
176 sprintf (post, "...[x%d]...)", nd-dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
177 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
178 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
179 const char *v; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
180 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
181 if (var[0] == '\0' || var == "<unknown>") |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
182 v = "index "; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
183 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
184 v = var.c_str (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
185 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
186 std::string tmp_idx = idx (); |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
187 snprintf (output, buf_len, "%s%s%s%s", v, pre, tmp_idx.c_str (), post); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
188 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
189 return output; |
11135 | 190 } |
191 | |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
192 class invalid_index : public index_exception |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
193 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
194 public: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
195 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
196 invalid_index (const std::string& value, octave_idx_type ndim, |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
197 octave_idx_type dimen) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
198 : index_exception (value, ndim, dimen) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
199 { } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
200 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
201 std::string details (void) const |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
202 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
203 #ifdef USE_64_BIT_IDX_T |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
204 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:
19697
diff
changeset
|
205 #else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
206 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:
19697
diff
changeset
|
207 #endif |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
208 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
209 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
210 // ID of error to throw |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
211 const char *err_id (void) const |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
212 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
213 return error_id_invalid_index; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
214 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
215 }; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
216 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
217 // Complain if an index is negative, fractional, or too big. |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
218 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
219 void |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
220 gripe_invalid_index (const std::string& idx, octave_idx_type nd, |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
221 octave_idx_type dim, const std::string&) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
222 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
223 invalid_index e (idx, nd, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
224 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
225 throw e; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
226 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
227 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
228 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
229 gripe_invalid_index (octave_idx_type n, octave_idx_type nd, |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
230 octave_idx_type dim, const std::string& var) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
231 { |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
232 // Note: log10 (2^63) = 19 digits. |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
233 char buf[64]; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
234 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
235 sprintf (buf, "%d", n+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
236 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
237 gripe_invalid_index (buf, nd, dim, var); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
238 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
239 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
240 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
241 gripe_invalid_index (double n, octave_idx_type nd, octave_idx_type dim, |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
242 const std::string& var) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
243 { |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
244 char buf[64]; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
245 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
246 sprintf (buf, "%g", n+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
247 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
248 gripe_invalid_index (buf, nd, dim, var); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
249 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
250 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
251 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
252 // 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:
19697
diff
changeset
|
253 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
254 class out_of_range : public index_exception |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
255 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
256 public: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
257 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
258 out_of_range (const std::string& value, octave_idx_type nd_in, |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
259 octave_idx_type dim_in) |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
260 : index_exception (value, nd_in, dim_in), extent (0) |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
261 { } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
262 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
263 std::string details (void) const |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
264 { |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
265 std::string expl; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
266 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
267 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:
19697
diff
changeset
|
268 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
269 if (var != "") |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
270 expl = "but " + var + " has size "; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
271 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
272 expl = "but object has size "; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
273 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
274 expl = expl + size.str ('x'); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
275 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
276 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
277 { |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
278 char buf[64]; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
279 sprintf (buf, "%d", extent); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
280 expl = "out of bound " + std::string (buf); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
281 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
282 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
283 return expl; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
284 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
285 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
286 // ID of error to throw. |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
287 const char *err_id (void) const |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
288 { |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
289 return error_id_index_out_of_bounds; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
290 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
291 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
292 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:
19697
diff
changeset
|
293 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
294 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:
19697
diff
changeset
|
295 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
296 private: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
297 |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
298 dim_vector size; // dimension of object being accessed |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
299 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
300 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:
19697
diff
changeset
|
301 }; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
302 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
303 // 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:
19697
diff
changeset
|
304 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
305 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:
19697
diff
changeset
|
306 octave_idx_type ext) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
307 { |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
308 char buf[64]; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
309 sprintf (buf, "%d", idx); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
310 out_of_range e (buf, nd, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
311 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
312 e.set_extent (ext); |
20651
c1d94e5cd5ea
catch index_exception by const reference where possible
John W. Eaton <jwe@octave.org>
parents:
20616
diff
changeset
|
313 dim_vector d (1,1,1,1,1,1,1); // make explain give extent not size |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
314 e.set_size (d); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
315 throw e; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
316 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
317 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
318 // 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:
19697
diff
changeset
|
319 void |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
320 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:
19697
diff
changeset
|
321 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:
19697
diff
changeset
|
322 { |
20616
e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
Rik <rik@octave.org>
parents:
20542
diff
changeset
|
323 char buf[64]; |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
324 sprintf (buf, "%d", idx); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
325 out_of_range e (buf, nd, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
326 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
327 e.set_extent (ext); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
328 e.set_size (d); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
329 throw e; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
330 } |
11135 | 331 |
332 void | |
333 gripe_invalid_resize (void) | |
334 { | |
335 (*current_liboctave_error_with_id_handler) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
336 ("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
|
337 "Invalid resizing operation or ambiguous assignment to an out-of-bounds array element"); |
11135 | 338 } |
339 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
340 void |
19408
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
341 gripe_singular_matrix (double rcond) |
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 if (rcond == 0.0) |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
344 { |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
345 (*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
|
346 (warning_id_singular_matrix, |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
347 "matrix singular to machine precision"); |
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 else |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
350 { |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
351 (*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
|
352 (warning_id_nearly_singular_matrix, |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
353 "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
|
354 } |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
355 } |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
356 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
357 /* Tests in test/index.tst */ |