Mercurial > octave
annotate libinterp/corefcn/error.cc @ 20828:7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
* error.cc (Flasterror, Flastwarning): If nargin == 1 then clear
Vlast_error_id. Remove retval declaration and use 'return ovl()' to return
multiple output values.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 08 Dec 2015 09:55:51 -0800 |
parents | b3f985199f3f |
children | 543eca132fa0 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19597
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1192 | 24 #include <config.h> |
1 | 25 #endif |
26 | |
1343 | 27 #include <cstdarg> |
1633 | 28 #include <cstring> |
1343 | 29 |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
30 #include <iomanip> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 #include <iostream> |
5765 | 32 #include <sstream> |
1728 | 33 #include <string> |
34 | |
1352 | 35 #include "defun.h" |
1 | 36 #include "error.h" |
3707 | 37 #include "input.h" |
1742 | 38 #include "pager.h" |
1352 | 39 #include "oct-obj.h" |
5567 | 40 #include "oct-map.h" |
1352 | 41 #include "utils.h" |
2370 | 42 #include "ov.h" |
3707 | 43 #include "ov-usr-fcn.h" |
18742
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
44 #include "pt-eval.h" |
3707 | 45 #include "pt-pr-code.h" |
46 #include "pt-stmt.h" | |
47 #include "toplev.h" | |
48 #include "unwind-prot.h" | |
2370 | 49 #include "variables.h" |
1 | 50 |
2174 | 51 // TRUE means that Octave will try to beep obnoxiously before printing |
52 // error messages. | |
5794 | 53 static bool Vbeep_on_error = false; |
2174 | 54 |
3707 | 55 // TRUE means that Octave will try to enter the debugger when an error |
56 // is encountered. This will also inhibit printing of the normal | |
57 // traceback message (you will only see the top-level error message). | |
7353 | 58 bool Vdebug_on_error = false; |
3707 | 59 |
60 // TRUE means that Octave will try to enter the debugger when a warning | |
61 // is encountered. | |
7353 | 62 bool Vdebug_on_warning = false; |
3707 | 63 |
5567 | 64 // TRUE means that Octave will try to display a stack trace when a |
65 // warning is encountered. | |
18128
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
66 static bool Vbacktrace_on_warning = true; |
5567 | 67 |
68 // TRUE means that Octave will print a verbose warning. Currently unused. | |
69 static bool Vverbose_warning; | |
70 | |
18742
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
71 // TRUE means that Octave will print no warnings, but lastwarn will be updated |
5582 | 72 static bool Vquiet_warning = false; |
73 | |
5567 | 74 // A structure containing (most of) the current state of warnings. |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
75 static octave_map warning_options; |
5567 | 76 |
3935 | 77 // The text of the last error message. |
78 static std::string Vlast_error_message; | |
79 | |
3934 | 80 // The text of the last warning message. |
81 static std::string Vlast_warning_message; | |
82 | |
5567 | 83 // The last warning message id. |
84 static std::string Vlast_warning_id; | |
3934 | 85 |
5567 | 86 // The last error message id. |
87 static std::string Vlast_error_id; | |
3934 | 88 |
6361 | 89 // The last file in which an error occured |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
90 static octave_map Vlast_error_stack; |
6361 | 91 |
143 | 92 // Current error state. |
3935 | 93 // |
94 // Valid values: | |
95 // | |
96 // 0: no error | |
97 // 1: an error has occurred | |
98 // | |
672 | 99 int error_state = 0; |
100 | |
1489 | 101 // Tell the error handler whether to print messages, or just store |
102 // them for later. Used for handling errors in eval() and | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
103 // the 'unwind_protect' statement. |
4699 | 104 int buffer_error_messages = 0; |
1489 | 105 |
3815 | 106 // TRUE means error messages are turned off. |
107 bool discard_error_messages = false; | |
108 | |
4452 | 109 // TRUE means warning messages are turned off. |
110 bool discard_warning_messages = false; | |
111 | |
4318 | 112 void |
113 reset_error_handler (void) | |
114 { | |
4699 | 115 buffer_error_messages = 0; |
4318 | 116 discard_error_messages = false; |
117 } | |
118 | |
5567 | 119 static void |
5794 | 120 initialize_warning_options (const std::string& state) |
5567 | 121 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
122 octave_scalar_map initw; |
5567 | 123 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
124 initw.setfield ("identifier", "all"); |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
125 initw.setfield ("state", state); |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
126 |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
127 warning_options = initw; |
5567 | 128 } |
129 | |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
130 static octave_map |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
131 initialize_last_error_stack (void) |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
132 { |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
133 return octave_call_stack::empty_backtrace (); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
134 } |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
135 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
136 static void |
4732 | 137 verror (bool save_last_error, std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 const char *name, const char *id, const char *fmt, va_list args, |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
139 bool with_cfn = false) |
1 | 140 { |
3815 | 141 if (discard_error_messages) |
142 return; | |
143 | |
3585 | 144 if (! buffer_error_messages) |
145 flush_octave_stdout (); | |
914 | 146 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 // FIXME: we really want to capture the message before it has all the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
148 // formatting goop attached to it. We probably also want just the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
149 // message, not the traceback information. |
3935 | 150 |
7877 | 151 std::ostringstream output_buf; |
152 | |
153 octave_vformat (output_buf, fmt, args); | |
154 | |
155 std::string base_msg = output_buf.str (); | |
156 | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
157 bool to_beep_or_not_to_beep_p = Vbeep_on_error; |
7877 | 158 |
159 std::string msg_string; | |
160 | |
161 if (to_beep_or_not_to_beep_p) | |
162 msg_string = "\a"; | |
163 | |
164 if (name) | |
165 msg_string += std::string (name) + ": "; | |
166 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
167 // If with_fcn is specified, we'll attempt to prefix the message with the name |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
168 // of the current executing function. But we'll do so only if: |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
169 // 1. the name is not empty (anonymous function) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
170 // 2. it is not already there (including the following colon) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
171 if (with_cfn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
172 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
173 octave_function *curfcn = octave_call_stack::current (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
174 if (curfcn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
175 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
176 std::string cfn = curfcn->name (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
177 if (! cfn.empty ()) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
178 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
179 cfn += ':'; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
180 if (cfn.length () > base_msg.length () |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
181 || base_msg.compare (0, cfn.length (), cfn) != 0) |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
182 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
183 msg_string += cfn + ' '; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
184 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
185 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
186 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
187 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
188 |
7880 | 189 msg_string += base_msg + "\n"; |
3935 | 190 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
191 if (save_last_error) |
3935 | 192 { |
193 // This is the first error in a possible series. | |
5567 | 194 |
195 Vlast_error_id = id; | |
7877 | 196 Vlast_error_message = base_msg; |
6361 | 197 |
7877 | 198 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
6361 | 199 |
7877 | 200 if (fcn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
201 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 octave_idx_type curr_frame = -1; |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
203 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 } |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
206 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 Vlast_error_stack = initialize_last_error_stack (); |
3935 | 208 } |
209 | |
13987
2c0765c14e4f
eliminate unused error message buffer
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
210 if (! buffer_error_messages) |
1489 | 211 { |
3935 | 212 octave_diary << msg_string; |
4732 | 213 os << msg_string; |
1489 | 214 } |
1 | 215 } |
216 | |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
217 static void |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
218 pr_where_2 (std::ostream& os, const char *fmt, va_list args) |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
219 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
220 if (fmt) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
221 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
222 if (*fmt) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
223 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
224 size_t len = strlen (fmt); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
225 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
226 if (len > 0) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
227 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
228 if (fmt[len - 1] == '\n') |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
229 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
230 if (len > 1) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
231 { |
20827
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
232 std::string tmp_fmt (fmt, len - 1); |
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
233 verror (false, os, 0, "", tmp_fmt.c_str (), args); |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
234 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
235 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
236 else |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
237 verror (false, os, 0, "", fmt, args); |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
238 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
239 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
240 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
241 else |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
242 panic ("pr_where_2: invalid format"); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
243 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
244 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
245 static void |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
246 pr_where_1 (std::ostream& os, const char *fmt, ...) |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
247 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
248 va_list args; |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
249 va_start (args, fmt); |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
250 pr_where_2 (os, fmt, args); |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
251 va_end (args); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
252 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
253 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
254 static void |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
255 pr_where (std::ostream& os, const char *who) |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
256 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
257 std::list<octave_call_stack::stack_frame> frames |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
258 = octave_call_stack::backtrace_frames (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
259 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
260 size_t nframes = frames.size (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
261 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
262 if (nframes > 0) |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
263 pr_where_1 (os, "%s: called from\n", who); |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
264 |
20511
9502e0142c19
Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents:
20181
diff
changeset
|
265 // Print the error message only if it is different from the previous one; |
9502e0142c19
Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents:
20181
diff
changeset
|
266 // Makes the output more concise and readable. |
9502e0142c19
Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents:
20181
diff
changeset
|
267 frames.unique (); |
9502e0142c19
Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents:
20181
diff
changeset
|
268 |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
269 for (std::list<octave_call_stack::stack_frame>::const_iterator p = frames.begin (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
270 p != frames.end (); p++) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
271 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
272 const octave_call_stack::stack_frame& elt = *p; |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
273 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
274 std::string fcn_name = elt.fcn_name (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
275 int line = elt.line (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
276 int column = elt.column (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
277 |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
278 pr_where_1 (os, " %s at line %d column %d\n", |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
279 fcn_name.c_str (), line, column); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
280 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
281 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
282 |
20780
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
283 static octave_execution_exception |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
284 make_execution_exception (const char *who) |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
285 { |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
286 std::ostringstream buf; |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
287 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
288 pr_where (buf, who); |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
289 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
290 octave_execution_exception retval; |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
291 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
292 retval.set_stack_trace (buf.str ()); |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
293 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
294 return retval; |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
295 } |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
296 |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
297 static void |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
298 maybe_enter_debugger (octave_execution_exception& e, |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
299 bool show_stack_trace = false) |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
300 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
301 if ((interactive || forced_interactive) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
302 && Vdebug_on_error && octave_call_stack::caller_user_code ()) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
303 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
304 unwind_protect frame; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
305 frame.protect_var (Vdebug_on_error); |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
306 Vdebug_on_error = false; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
307 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
308 tree_evaluator::debug_mode = true; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
309 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
310 tree_evaluator::current_frame = octave_call_stack::current_frame (); |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
311 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
312 if (show_stack_trace) |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
313 { |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
314 std::string stack_trace = e.info (); |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
315 |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
316 if (! stack_trace.empty ()) |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
317 { |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
318 std::cerr << stack_trace; |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
319 |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
320 e.set_stack_trace (); |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
321 } |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
322 } |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
323 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
324 do_keyboard (octave_value_list ()); |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
325 } |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
326 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
327 |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
328 // Warning messages are never buffered. |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
329 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
330 static void |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
331 vwarning (const char *name, const char *id, const char *fmt, va_list args) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
332 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
333 if (discard_warning_messages) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
334 return; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
335 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
336 flush_octave_stdout (); |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
337 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
338 std::ostringstream output_buf; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
339 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
340 octave_vformat (output_buf, fmt, args); |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
341 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
342 // FIXME: we really want to capture the message before it has all the |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
343 // formatting goop attached to it. We probably also want just the |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
344 // message, not the traceback information. |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
345 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
346 std::string base_msg = output_buf.str (); |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
347 std::string msg_string; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
348 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
349 if (name) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
350 msg_string = std::string (name) + ": "; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
351 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
352 msg_string += base_msg + "\n"; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
353 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
354 Vlast_warning_id = id; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
355 Vlast_warning_message = base_msg; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
356 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
357 if (! Vquiet_warning) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
358 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
359 octave_diary << msg_string; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
360 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
361 std::cerr << msg_string; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
362 } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
363 } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
364 |
1 | 365 void |
6338 | 366 vmessage (const char *name, const char *fmt, va_list args) |
367 { | |
368 verror (false, std::cerr, name, "", fmt, args); | |
369 } | |
370 | |
371 void | |
1 | 372 message (const char *name, const char *fmt, ...) |
373 { | |
374 va_list args; | |
375 va_start (args, fmt); | |
6338 | 376 vmessage (name, fmt, args); |
1 | 377 va_end (args); |
378 } | |
379 | |
380 void | |
6338 | 381 vmessage_with_id (const char *name, const char *id, const char *fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 va_list args) |
6338 | 383 { |
384 verror (false, std::cerr, name, id, fmt, args); | |
385 } | |
386 | |
387 void | |
5567 | 388 message_with_id (const char *name, const char *id, const char *fmt, ...) |
389 { | |
390 va_list args; | |
391 va_start (args, fmt); | |
6338 | 392 vmessage_with_id (name, id, fmt, args); |
5567 | 393 va_end (args); |
394 } | |
395 | |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
396 static void |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
397 usage_1 (octave_execution_exception& e, const char *id, |
20826
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
398 const char *fmt, va_list args) GCC_ATTR_NORETURN; |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
399 |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
400 static void |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
401 usage_1 (octave_execution_exception& e, const char *id, |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
402 const char *fmt, va_list args) |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
403 { |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
404 verror (true, std::cerr, "usage", id, fmt, args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
405 |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
406 maybe_enter_debugger (e); |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
407 |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
408 throw e; |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
409 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
410 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
411 static void |
20826
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
412 usage_1 (const char *id, const char *fmt, va_list args) GCC_ATTR_NORETURN; |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
413 |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
414 static void |
5567 | 415 usage_1 (const char *id, const char *fmt, va_list args) |
416 { | |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
417 octave_execution_exception e = make_execution_exception ("usage"); |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
418 |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
419 usage_1 (e, id, fmt, args); |
5567 | 420 } |
421 | |
422 void | |
6338 | 423 vusage (const char *fmt, va_list args) |
424 { | |
425 usage_1 ("", fmt, args); | |
426 } | |
427 | |
428 void | |
1 | 429 usage (const char *fmt, ...) |
430 { | |
431 va_list args; | |
432 va_start (args, fmt); | |
6338 | 433 vusage (fmt, args); |
5567 | 434 va_end (args); |
435 } | |
436 | |
437 void | |
6338 | 438 vusage_with_id (const char *id, const char *fmt, va_list args) |
439 { | |
440 usage_1 (id, fmt, args); | |
441 } | |
442 | |
443 void | |
5567 | 444 usage_with_id (const char *id, const char *fmt, ...) |
445 { | |
446 va_list args; | |
447 va_start (args, fmt); | |
6338 | 448 vusage_with_id (id, fmt, args); |
1 | 449 va_end (args); |
450 } | |
451 | |
3707 | 452 static void |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
453 error_1 (octave_execution_exception& e, std::ostream& os, |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
454 const char *name, const char *id, const char *fmt, |
20826
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
455 va_list args, bool with_cfn = false) GCC_ATTR_NORETURN; |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
456 |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
457 static void |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
458 error_1 (octave_execution_exception& e, std::ostream& os, |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
459 const char *name, const char *id, const char *fmt, |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
460 va_list args, bool with_cfn) |
6000 | 461 { |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
462 bool show_stack_trace = false; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
463 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
464 if (fmt) |
6000 | 465 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
466 if (*fmt) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
467 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
468 size_t len = strlen (fmt); |
6000 | 469 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
470 if (len > 0) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
471 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
472 if (fmt[len - 1] == '\n') |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
473 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
474 if (len > 1) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
475 { |
20827
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
476 std::string tmp_fmt (fmt, len - 1); |
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
477 verror (true, os, name, id, tmp_fmt.c_str (), |
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
478 args, with_cfn); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
479 } |
20822
40fc94a24a97
if error format ends with newline, suppress stack trace (bug #46608)
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
480 |
40fc94a24a97
if error format ends with newline, suppress stack trace (bug #46608)
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
481 // If format ends with newline, suppress stack trace. |
40fc94a24a97
if error format ends with newline, suppress stack trace (bug #46608)
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
482 e.set_stack_trace (); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
483 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
484 else |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
485 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
486 verror (true, os, name, id, fmt, args, with_cfn); |
18742
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
487 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
488 bool in_user_code = octave_call_stack::caller_user_code () != 0; |
18742
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
489 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
490 if (in_user_code && ! discard_error_messages) |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
491 show_stack_trace = true; |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
492 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
493 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
494 } |
6000 | 495 } |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
496 else |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
497 panic ("error_1: invalid format"); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
498 |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
499 maybe_enter_debugger (e, show_stack_trace); |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
500 |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
501 throw e; |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
502 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
503 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
504 static void |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
505 error_1 (std::ostream& os, const char *name, const char *id, |
20826
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
506 const char *fmt, va_list args, |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
507 bool with_cfn = false) GCC_ATTR_NORETURN; |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
508 |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
509 static void |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
510 error_1 (std::ostream& os, const char *name, const char *id, |
779898f2a02a
tag error and usage functions with noreturn attribute
John W. Eaton <jwe@octave.org>
parents:
20822
diff
changeset
|
511 const char *fmt, va_list args, bool with_cfn) |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
512 { |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
513 octave_execution_exception e = make_execution_exception ("error"); |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
514 |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
515 error_1 (e, os, name, id, fmt, args, with_cfn); |
6000 | 516 } |
517 | |
518 void | |
6338 | 519 verror (const char *fmt, va_list args) |
520 { | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
521 error_1 (std::cerr, "error", "", fmt, args); |
6338 | 522 } |
523 | |
524 void | |
6000 | 525 error (const char *fmt, ...) |
526 { | |
527 va_list args; | |
528 va_start (args, fmt); | |
6338 | 529 verror (fmt, args); |
6000 | 530 va_end (args); |
531 } | |
532 | |
533 void | |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
534 verror (octave_execution_exception& e, const char *fmt, va_list args) |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
535 { |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
536 error_1 (e, std::cerr, "error", "", fmt, args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
537 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
538 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
539 void |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20780
diff
changeset
|
540 error (octave_execution_exception& e, const char *fmt, ...) |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
541 { |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
542 va_list args; |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
543 va_start (args, fmt); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
544 verror (e, fmt, args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
545 va_end (args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
546 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
547 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
548 void |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
549 verror_with_cfn (const char *fmt, va_list args) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
550 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
551 error_1 (std::cerr, "error", "", fmt, args, true); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
552 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
553 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
554 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
555 error_with_cfn (const char *fmt, ...) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
556 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
557 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
558 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
559 verror_with_cfn (fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
560 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
561 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
562 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
563 void |
6338 | 564 verror_with_id (const char *id, const char *fmt, va_list args) |
565 { | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
566 error_1 (std::cerr, "error", id, fmt, args); |
6338 | 567 } |
568 | |
569 void | |
6000 | 570 error_with_id (const char *id, const char *fmt, ...) |
571 { | |
572 va_list args; | |
573 va_start (args, fmt); | |
6338 | 574 verror_with_id (id, fmt, args); |
6000 | 575 va_end (args); |
576 } | |
577 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
578 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
579 verror_with_id_cfn (const char *id, const char *fmt, va_list args) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
580 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
581 error_1 (std::cerr, "error", id, fmt, args, true); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
582 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
583 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
584 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
585 error_with_id_cfn (const char *id, const char *fmt, ...) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
586 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
587 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
588 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
589 verror_with_id_cfn (id, fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
590 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
591 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
592 |
5567 | 593 static int |
594 check_state (const std::string& state) | |
595 { | |
596 // -1: not found | |
597 // 0: found, "off" | |
598 // 1: found, "on" | |
599 // 2: found, "error" | |
600 | |
601 if (state == "off") | |
602 return 0; | |
603 else if (state == "on") | |
604 return 1; | |
605 else if (state == "error") | |
606 return 2; | |
607 else | |
608 return -1; | |
609 } | |
610 | |
611 // For given warning ID, return 0 if warnings are disabled, 1 if | |
14042
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
612 // enabled, and 2 if the given ID should be an error instead of a |
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
613 // warning. |
5567 | 614 |
5781 | 615 int |
5567 | 616 warning_enabled (const std::string& id) |
1 | 617 { |
5567 | 618 int retval = 0; |
619 | |
620 int all_state = -1; | |
621 int id_state = -1; | |
622 | |
623 octave_idx_type nel = warning_options.numel (); | |
624 | |
625 if (nel > 0) | |
626 { | |
627 Cell identifier = warning_options.contents ("identifier"); | |
628 Cell state = warning_options.contents ("state"); | |
629 | |
630 bool all_found = false; | |
631 bool id_found = false; | |
632 | |
633 for (octave_idx_type i = 0; i < nel; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
634 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
635 octave_value ov = identifier(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
636 std::string ovs = ov.string_value (); |
5567 | 637 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
638 if (! all_found && ovs == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
639 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
640 all_state = check_state (state(i).string_value ()); |
5567 | 641 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
642 if (all_state >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
643 all_found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
644 } |
5567 | 645 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
646 if (! id_found && ovs == id) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
648 id_state = check_state (state(i).string_value ()); |
5567 | 649 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
650 if (id_state >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
651 id_found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 } |
5567 | 653 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
654 if (all_found && id_found) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
655 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
656 } |
5567 | 657 } |
658 | |
14042
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
659 // If "all" is not present, assume warnings are enabled. |
5567 | 660 if (all_state == -1) |
14042
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
661 all_state = 1; |
5567 | 662 |
663 if (all_state == 0) | |
664 { | |
665 if (id_state >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
666 retval = id_state; |
5567 | 667 } |
668 else if (all_state == 1) | |
669 { | |
670 if (id_state == 0 || id_state == 2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 retval = id_state; |
5567 | 672 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 retval = all_state; |
5567 | 674 } |
675 else if (all_state == 2) | |
7206 | 676 { |
677 if (id_state == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
678 retval= id_state; |
7206 | 679 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 retval = all_state; |
7206 | 681 } |
5567 | 682 |
683 return retval; | |
684 } | |
685 | |
686 static void | |
687 warning_1 (const char *id, const char *fmt, va_list args) | |
688 { | |
689 int warn_opt = warning_enabled (id); | |
690 | |
691 if (warn_opt == 2) | |
692 { | |
693 // Handle this warning as an error. | |
694 | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
695 error_1 (std::cerr, "error", id, fmt, args); |
5567 | 696 } |
697 else if (warn_opt == 1) | |
3934 | 698 { |
20140
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
699 bool fmt_suppresses_backtrace = false; |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
700 size_t fmt_len = fmt ? strlen (fmt) : 0; |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
701 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n'); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
702 |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
703 if (fmt_suppresses_backtrace && fmt_len > 1) |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
704 { |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
705 // Strip newline before issuing warning |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
706 std::string tmp_fmt (fmt, fmt_len - 1); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
707 vwarning ("warning", id, tmp_fmt.c_str (), args); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
708 } |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
709 else |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20130
diff
changeset
|
710 vwarning ("warning", id, fmt, args); |
8973 | 711 |
20127
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20101
diff
changeset
|
712 bool in_user_code = octave_call_stack::caller_user_code () != 0; |
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20101
diff
changeset
|
713 |
20130
0aed244dbdb3
don't print stack trace if warning format ends with newline character
John W. Eaton <jwe@octave.org>
parents:
20127
diff
changeset
|
714 if (! fmt_suppresses_backtrace && in_user_code |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
715 && Vbacktrace_on_warning |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
716 && ! discard_warning_messages) |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
717 pr_where (std::cerr, "warning"); |
3707 | 718 |
3934 | 719 if ((interactive || forced_interactive) |
20127
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20101
diff
changeset
|
720 && Vdebug_on_warning && in_user_code) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
721 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
722 unwind_protect frame; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
723 frame.protect_var (Vdebug_on_warning); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 Vdebug_on_warning = false; |
3707 | 725 |
18742
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
726 tree_evaluator::debug_mode = true; |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
727 |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
728 tree_evaluator::current_frame = octave_call_stack::current_frame (); |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
729 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 do_keyboard (octave_value_list ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
731 } |
3707 | 732 } |
1 | 733 } |
734 | |
735 void | |
6338 | 736 vwarning (const char *fmt, va_list args) |
737 { | |
738 warning_1 ("", fmt, args); | |
739 } | |
740 | |
741 void | |
5567 | 742 warning (const char *fmt, ...) |
743 { | |
744 va_list args; | |
745 va_start (args, fmt); | |
6338 | 746 vwarning (fmt, args); |
5567 | 747 va_end (args); |
748 } | |
749 | |
750 void | |
6338 | 751 vwarning_with_id (const char *id, const char *fmt, va_list args) |
752 { | |
753 warning_1 (id, fmt, args); | |
754 } | |
755 | |
756 void | |
5567 | 757 warning_with_id (const char *id, const char *fmt, ...) |
758 { | |
759 va_list args; | |
760 va_start (args, fmt); | |
6338 | 761 vwarning_with_id (id, fmt, args); |
5567 | 762 va_end (args); |
763 } | |
764 | |
765 void | |
6338 | 766 vparse_error (const char *fmt, va_list args) |
767 { | |
768 error_1 (std::cerr, 0, "", fmt, args); | |
769 } | |
770 | |
771 void | |
1005 | 772 parse_error (const char *fmt, ...) |
773 { | |
774 va_list args; | |
775 va_start (args, fmt); | |
6338 | 776 vparse_error (fmt, args); |
5567 | 777 va_end (args); |
778 } | |
779 | |
780 void | |
6338 | 781 vparse_error_with_id (const char *id, const char *fmt, va_list args) |
782 { | |
783 error_1 (std::cerr, 0, id, fmt, args); | |
784 } | |
785 | |
786 void | |
5567 | 787 parse_error_with_id (const char *id, const char *fmt, ...) |
788 { | |
789 va_list args; | |
790 va_start (args, fmt); | |
6338 | 791 vparse_error_with_id (id, fmt, args); |
1 | 792 va_end (args); |
793 } | |
794 | |
189 | 795 void |
6361 | 796 rethrow_error (const char *id, const char *fmt, ...) |
797 { | |
798 va_list args; | |
799 va_start (args, fmt); | |
6640 | 800 error_1 (std::cerr, 0, id, fmt, args); |
6361 | 801 va_end (args); |
802 } | |
803 | |
804 void | |
1 | 805 panic (const char *fmt, ...) |
806 { | |
807 va_list args; | |
808 va_start (args, fmt); | |
4699 | 809 buffer_error_messages = 0; |
3815 | 810 discard_error_messages = false; |
5567 | 811 verror (false, std::cerr, "panic", "", fmt, args); |
1 | 812 va_end (args); |
813 abort (); | |
814 } | |
815 | |
4732 | 816 static void |
817 defun_usage_message_1 (const char *fmt, ...) | |
818 { | |
819 va_list args; | |
820 va_start (args, fmt); | |
5567 | 821 error_1 (octave_stdout, 0, "", fmt, args); |
4732 | 822 va_end (args); |
823 } | |
824 | |
825 void | |
826 defun_usage_message (const std::string& msg) | |
827 { | |
828 defun_usage_message_1 ("%s", msg.c_str ()); | |
829 } | |
830 | |
5567 | 831 typedef void (*error_fun)(const char *, const char *, ...); |
1489 | 832 |
2086 | 833 extern octave_value_list Fsprintf (const octave_value_list&, int); |
1489 | 834 |
3934 | 835 static std::string |
5567 | 836 handle_message (error_fun f, const char *id, const char *msg, |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
837 const octave_value_list& args, bool have_fmt) |
528 | 838 { |
3934 | 839 std::string retval; |
528 | 840 |
3523 | 841 std::string tstr; |
1728 | 842 |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
843 if (args.length () > 0) |
528 | 844 { |
3066 | 845 octave_value arg; |
846 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
847 if (have_fmt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
848 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
849 octave_value_list tmp = Fsprintf (args, 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
850 arg = tmp(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
851 } |
3066 | 852 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
853 arg = args(0); |
2745 | 854 |
855 if (arg.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
856 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
857 if (arg.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
858 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
859 tstr = arg.string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
860 msg = tstr.c_str (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
861 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 if (! msg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
863 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
864 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 else if (arg.is_empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 } |
528 | 868 } |
869 | |
1489 | 870 // Ugh. |
871 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
872 size_t len = strlen (msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
873 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
874 if (len > 0) |
1489 | 875 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
876 if (msg[len - 1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 if (len > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 { |
20827
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
880 std::string tmp_msg (msg, len - 1); |
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
881 f (id, "%s\n", tmp_msg.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 retval = tmp_msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
884 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
885 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
886 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 f (id, "%s", msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
888 retval = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 } |
3934 | 890 } |
528 | 891 |
892 return retval; | |
893 } | |
894 | |
6361 | 895 DEFUN (rethrow, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
896 "-*- texinfo -*-\n\ |
6361 | 897 @deftypefn {Built-in Function} {} rethrow (@var{err})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
898 Reissue a previous error as defined by @var{err}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
899 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
900 @var{err} is a structure that must contain at least the @qcode{\"message\"}\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
901 and @qcode{\"identifier\"} fields. @var{err} can also contain a field\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
902 @qcode{\"stack\"} that gives information on the assumed location of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
903 error. Typically @var{err} is returned from @code{lasterror}.\n\ |
6361 | 904 @seealso{lasterror, lasterr, error}\n\ |
905 @end deftypefn") | |
906 { | |
907 octave_value retval; | |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
908 |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
909 if (args.length () != 1) |
6959 | 910 print_usage (); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
911 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
912 const octave_scalar_map err = args(0).scalar_map_value (); |
6361 | 913 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
914 if (err.contains ("message") && err.contains ("identifier")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
915 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
916 std::string msg = err.contents ("message").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
917 std::string id = err.contents ("identifier").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
918 int len = msg.length (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
919 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
920 std::string file; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
921 std::string nm; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
922 int l = -1; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
923 int c = -1; |
6483 | 924 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
925 octave_map err_stack = initialize_last_error_stack (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
926 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
927 if (err.contains ("stack")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
928 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
929 err_stack = err.contents ("stack").map_value (); |
6483 | 930 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
931 if (err_stack.numel () > 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
932 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
933 if (err_stack.contains ("file")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
934 file = err_stack.contents ("file")(0).string_value (); |
6640 | 935 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
936 if (err_stack.contains ("name")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
937 nm = err_stack.contents ("name")(0).string_value (); |
6361 | 938 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
939 if (err_stack.contains ("line")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
940 l = err_stack.contents ("line")(0).nint_value (); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
941 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
942 if (err_stack.contains ("column")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
943 c = err_stack.contents ("column")(0).nint_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
944 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
945 } |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
946 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
947 // Ugh. |
20827
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
948 std::string tmp_msg (msg); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
949 if (tmp_msg[len-1] == '\n') |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
950 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
951 if (len > 1) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
952 { |
20827
b3f985199f3f
eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents:
20826
diff
changeset
|
953 tmp_msg.erase (len - 1); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
954 rethrow_error (id.c_str (), "%s\n", tmp_msg); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
955 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
956 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
957 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
958 rethrow_error (id.c_str (), "%s", tmp_msg); |
6361 | 959 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
960 // FIXME: is this the right thing to do for Vlast_error_stack? |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
961 // Should it be saved and restored with unwind_protect? |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
962 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
963 Vlast_error_stack = err_stack; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
964 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
965 if (err.contains ("stack")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
966 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
967 if (file.empty ()) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
968 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
969 if (nm.empty ()) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
970 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
971 if (l > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
972 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
973 if (c > 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
974 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
975 "error: near line %d, column %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
976 l, c); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
977 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
978 pr_where_1 (std::cerr, "error: near line %d", l); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
979 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
980 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
981 else |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
982 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
983 if (l > 0) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
984 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
985 if (c > 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
986 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
987 "error: called from '%s' near line %d, column %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
988 nm.c_str (), l, c); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
989 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
990 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
991 "error: called from '%d' near line %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
992 nm.c_str (), l); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
993 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
994 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
995 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
996 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
997 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
998 if (nm.empty ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
999 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1000 if (l > 0) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1001 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1002 if (c > 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1003 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1004 "error: in file %s near line %d, column %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1005 file.c_str (), l, c); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1006 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1007 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1008 "error: in file %s near line %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1009 file.c_str (), l); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1010 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1011 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1012 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1013 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1014 if (l > 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1015 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1016 if (c > 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1017 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1018 "error: called from '%s' in file %s near line %d, column %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1019 nm.c_str (), file.c_str (), l, c); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1020 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1021 pr_where_1 (std::cerr, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1022 "error: called from '%d' in file %s near line %d", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1023 nm.c_str (), file.c_str (), l); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1024 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1025 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1026 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 } |
6361 | 1028 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1029 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1030 error ("rethrow: ERR structure must contain the fields 'message and 'identifier'"); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1031 |
6361 | 1032 return retval; |
1033 } | |
1034 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1035 // Determine whether the first argument to error or warning function |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1036 // should be handled as the message identifier or as the format string. |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1037 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1038 static bool |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1039 maybe_extract_message_id (const std::string& caller, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1040 const octave_value_list& args, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1041 octave_value_list& nargs, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1042 std::string& id) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1043 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1044 nargs = args; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1045 id = std::string (); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1046 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1047 int nargin = args.length (); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1048 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1049 bool have_fmt = nargin > 1; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1050 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1051 if (nargin > 0) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1052 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1053 std::string arg1 = args(0).string_value (); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1054 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1055 // For compatibility with Matlab, an identifier must contain |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1056 // ':', but not at the beginning or the end, and it must not |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1057 // contain '%' (even if it is not a valid conversion |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1058 // operator) or whitespace. |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1059 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1060 if (arg1.find_first_of ("% \f\n\r\t\v") == std::string::npos |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1061 && arg1.find (':') != std::string::npos |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1062 && arg1[0] != ':' |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1063 && arg1[arg1.length ()-1] != ':') |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1064 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1065 if (nargin > 1) |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1066 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1067 id = arg1; |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1068 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1069 nargs.resize (nargin-1); |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1070 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1071 for (int i = 1; i < nargin; i++) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1072 nargs(i-1) = args(i); |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1073 } |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1074 else |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1075 nargs(0) = "call to " + caller |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1076 + " with message identifier requires message"; |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1077 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1078 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1079 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1080 return have_fmt; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1081 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1082 |
1957 | 1083 DEFUN (error, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1084 "-*- texinfo -*-\n\ |
10840 | 1085 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\ |
7252 | 1086 @deftypefnx {Built-in Function} {} error (@var{id}, @var{template}, @dots{})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1087 Display an error message and stop m-file execution.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1088 \n\ |
5781 | 1089 Format the optional arguments under the control of the template string\n\ |
1090 @var{template} using the same rules as the @code{printf} family of\n\ | |
1091 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
1092 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
1093 string @samp{error: }.\n\ | |
3373 | 1094 \n\ |
1095 Calling @code{error} also sets Octave's internal error state such that\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1096 control will return to the top level without evaluating any further\n\ |
3373 | 1097 commands. This is useful for aborting from functions or scripts.\n\ |
897 | 1098 \n\ |
19334
1213af866a89
doc: Fix backslash not showing in error/warning docs due to escape processing.
Rik <rik@octave.org>
parents:
18126
diff
changeset
|
1099 If the error message does not end with a newline character, Octave will\n\ |
3373 | 1100 print a traceback of all the function calls leading to the error. For\n\ |
1101 example, given the following function definitions:\n\ | |
1102 \n\ | |
1103 @example\n\ | |
1104 @group\n\ | |
6671 | 1105 function f () g (); end\n\ |
1106 function g () h (); end\n\ | |
3373 | 1107 function h () nargin == 1 || error (\"nargin != 1\"); end\n\ |
1108 @end group\n\ | |
1109 @end example\n\ | |
1489 | 1110 \n\ |
3373 | 1111 @noindent\n\ |
1112 calling the function @code{f} will result in a list of messages that\n\ | |
1113 can help you to quickly locate the exact location of the error:\n\ | |
1489 | 1114 \n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1115 @example\n\ |
3373 | 1116 @group\n\ |
1117 f ()\n\ | |
1118 error: nargin != 1\n\ | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1119 error: called from:\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1120 error: error at line -1, column -1\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1121 error: h at line 1, column 27\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1122 error: g at line 1, column 15\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1123 error: f at line 1, column 15\n\ |
3373 | 1124 @end group\n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1125 @end example\n\ |
3373 | 1126 \n\ |
19334
1213af866a89
doc: Fix backslash not showing in error/warning docs due to escape processing.
Rik <rik@octave.org>
parents:
18126
diff
changeset
|
1127 If the error message ends in a newline character, Octave will print the\n\ |
3373 | 1128 message but will not display any traceback messages as it returns\n\ |
1129 control to the top level. For example, modifying the error message\n\ | |
19334
1213af866a89
doc: Fix backslash not showing in error/warning docs due to escape processing.
Rik <rik@octave.org>
parents:
18126
diff
changeset
|
1130 in the previous example to end in a newline causes Octave to only print\n\ |
3373 | 1131 a single message:\n\ |
1132 \n\ | |
1133 @example\n\ | |
1134 @group\n\ | |
1135 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\ | |
1136 f ()\n\ | |
1137 error: nargin != 1\n\ | |
1138 @end group\n\ | |
1139 @end example\n\ | |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1140 \n\ |
16770
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1141 A null string (\"\") input to @code{error} will be ignored and the code\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1142 will continue running as if the statement were a NOP@. This is for\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1143 compatibility with @sc{matlab}. It also makes it possible to write code such\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1144 as\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1145 \n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1146 @example\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1147 @group\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1148 err_msg = \"\";\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1149 if (CONDITION 1)\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1150 err_msg = \"CONDITION 1 found\";\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1151 elseif (CONDITION2)\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1152 err_msg = \"CONDITION 2 found\";\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1153 @dots{}\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1154 endif\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1155 error (err_msg);\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1156 @end group\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1157 @end example\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1158 \n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1159 @noindent\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1160 which will only stop execution if an error has been found.\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1161 \n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1162 Implementation Note: For compatibility with @sc{matlab}, escape\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1163 sequences in @var{template} (e.g., @qcode{\"@xbackslashchar{}n\"} =>\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1164 newline) are processed regardless of whether @var{template} has been defined\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1165 with single quotes, as long as there are two or more input arguments. To\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1166 disable escape sequence expansion use a second backslash before the sequence\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1167 (e.g., @qcode{\"@xbackslashchar{}@xbackslashchar{}n\"}) or use the\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1168 @code{regexptranslate} function.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1169 @seealso{warning, lasterror}\n\ |
3373 | 1170 @end deftypefn") |
897 | 1171 { |
7252 | 1172 octave_value retval; |
1173 | |
1174 int nargin = args.length (); | |
1175 | |
1176 octave_value_list nargs = args; | |
1177 | |
1178 std::string id; | |
1179 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1180 if (nargin == 0) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1181 print_usage (); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1182 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1183 bool have_fmt = false; |
5567 | 1184 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1185 if (nargin == 1 && args(0).is_map ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1186 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1187 // empty struct is not an error. return and resume calling function. |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1188 if (args(0).is_empty ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1189 return retval; |
13709
a0875c6cab7e
error.cc: Don't complain if error struct input is empty (Matlab compatability)
Rik <octave@nomad.inbox5.com>
parents:
12705
diff
changeset
|
1190 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1191 octave_value_list tmp; |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1192 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1193 octave_scalar_map m = args(0).scalar_map_value (); |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1194 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1195 // empty struct is not an error. return and resume calling function. |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1196 if (m.nfields () == 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1197 return retval; |
12705
4972eb61c6d6
Fix bug with error() not accepting an empty struct input (Bug #33428).
Rik <octave@nomad.inbox5.com>
parents:
12704
diff
changeset
|
1198 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1199 if (m.contains ("message")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1200 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1201 octave_value c = m.getfield ("message"); |
7252 | 1202 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1203 if (c.is_string ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1204 nargs(0) = c.string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1205 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1206 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1207 if (m.contains ("identifier")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1208 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1209 octave_value c = m.getfield ("identifier"); |
7252 | 1210 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1211 if (c.is_string ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1212 id = c.string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1213 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1214 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1215 // FIXME: also need to handle "stack" field in error structure, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1216 // but that will require some more significant surgery on |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1217 // handle_message, error_with_id, etc. |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1218 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1219 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1220 have_fmt = maybe_extract_message_id ("error", args, nargs, id); |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1221 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1222 handle_message (error_with_id, id.c_str (), "unspecified error", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1223 nargs, have_fmt); |
7252 | 1224 |
3934 | 1225 return retval; |
1489 | 1226 } |
897 | 1227 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1228 static octave_scalar_map |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1229 warning_query (const std::string& id_arg) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1230 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1231 octave_scalar_map retval; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1232 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1233 std::string id = id_arg; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1234 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1235 if (id == "last") |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1236 id = Vlast_warning_id; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1237 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1238 Cell ident = warning_options.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1239 Cell state = warning_options.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1240 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1241 octave_idx_type nel = ident.numel (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1242 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1243 assert (nel != 0); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1244 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1245 bool found = false; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1246 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1247 std::string val; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1248 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1249 for (octave_idx_type i = 0; i < nel; i++) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1250 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1251 if (ident(i).string_value () == id) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1252 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1253 val = state(i).string_value (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1254 found = true; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1255 break; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1256 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1257 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1258 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1259 if (! found) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1260 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1261 for (octave_idx_type i = 0; i < nel; i++) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1262 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1263 if (ident(i).string_value () == "all") |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1264 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1265 val = state(i).string_value (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1266 found = true; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1267 break; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1268 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1269 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1270 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1271 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1272 // The warning state "all" is always supposed to remain in the list, |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1273 // so we should always find a state, either explicitly or by using the |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1274 // state for "all". |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1275 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1276 assert (found); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1277 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1278 retval.assign ("identifier", id); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1279 retval.assign ("state", val); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1280 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1281 return retval; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1282 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1283 |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1284 static std::string |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1285 default_warning_state (void) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1286 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1287 std::string retval = "on"; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1288 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1289 Cell ident = warning_options.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1290 Cell state = warning_options.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1291 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1292 octave_idx_type nel = ident.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1293 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1294 for (octave_idx_type i = 0; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1295 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1296 if (ident(i).string_value () == "all") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1297 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1298 retval = state(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1299 break; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1300 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1301 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1302 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1303 return retval; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1304 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1305 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1306 static void |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1307 display_warning_options (std::ostream& os) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1308 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1309 Cell ident = warning_options.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1310 Cell state = warning_options.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1311 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1312 octave_idx_type nel = ident.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1313 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1314 std::string all_state = default_warning_state (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1315 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1316 if (all_state == "on") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1317 os << "By default, warnings are enabled."; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1318 else if (all_state == "off") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1319 os << "By default, warnings are disabled."; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1320 else if (all_state == "error") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1321 os << "By default, warnings are treated as errors."; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1322 else |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1323 panic_impossible (); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19444
diff
changeset
|
1324 |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1325 if (nel > 1) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1326 os << "\n\n"; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1327 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1328 // The state for all is always supposed to be first in the list. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1329 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1330 for (octave_idx_type i = 1; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1331 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1332 std::string tid = ident(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1333 std::string tst = state(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1334 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1335 os << std::setw (7) << tst << " " << tid << "\n"; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1336 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1337 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1338 os << std::endl; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1339 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1340 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1341 static void |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1342 set_warning_option (const std::string& state, const std::string& ident) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1343 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1344 if (ident == "all") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1345 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1346 initialize_warning_options (state); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1347 return; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1348 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1349 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1350 std::string all_state = default_warning_state (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1351 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1352 if (state != "on" && state != "off" && state != "error") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1353 error ("invalid warning state: %s", state.c_str ()); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1354 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1355 Cell tid = warning_options.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1356 Cell tst = warning_options.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1357 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1358 octave_idx_type nel = tid.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1359 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1360 for (octave_idx_type i = 0; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1361 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1362 if (tid(i).string_value () == ident) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1363 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1364 // We found it in the current list of options. If the state |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1365 // for "all" is same as arg1, we can simply remove the item |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1366 // from the list. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1367 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1368 if (state == all_state) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1369 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1370 for (i = i + 1; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1371 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1372 tid(i-1) = tid(i); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1373 tst(i-1) = tst(i); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1374 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1375 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1376 tid.resize (dim_vector (1, nel-1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1377 tst.resize (dim_vector (1, nel-1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1378 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1379 else |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1380 tst(i) = state; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1381 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1382 warning_options.clear (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1383 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1384 warning_options.assign ("identifier", tid); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1385 warning_options.assign ("state", tst); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1386 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1387 return; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1388 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1389 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1390 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1391 // The option wasn't already in the list. Append it. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1392 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1393 tid.resize (dim_vector (1, nel+1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1394 tst.resize (dim_vector (1, nel+1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1395 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1396 tid(nel) = ident; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1397 tst(nel) = state; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1398 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1399 warning_options.clear (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1400 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1401 warning_options.assign ("identifier", tid); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1402 warning_options.assign ("state", tst); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1403 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1404 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
1405 DEFUN (warning, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1406 "-*- texinfo -*-\n\ |
10840 | 1407 @deftypefn {Built-in Function} {} warning (@var{template}, @dots{})\n\ |
7252 | 1408 @deftypefnx {Built-in Function} {} warning (@var{id}, @var{template}, @dots{})\n\ |
14072
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1409 @deftypefnx {Built-in Function} {} warning (\"on\", @var{id})\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1410 @deftypefnx {Built-in Function} {} warning (\"off\", @var{id})\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1411 @deftypefnx {Built-in Function} {} warning (\"query\", @var{id})\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1412 @deftypefnx {Built-in Function} {} warning (\"error\", @var{id})\n\ |
18128
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1413 @deftypefnx {Built-in Function} {} warning (@var{state}, \"backtrace\")\n\ |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1414 @deftypefnx {Built-in Function} {} warning (@var{state}, @var{id}, \"local\")\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1415 Display a warning message or control the behavior of Octave's warning system.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1416 \n\ |
5781 | 1417 Format the optional arguments under the control of the template string\n\ |
1418 @var{template} using the same rules as the @code{printf} family of\n\ | |
1419 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
1420 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
1421 string @samp{warning: }.\n\ | |
1422 You should use this function when you want to notify the user\n\ | |
3600 | 1423 of an unusual condition, but only when it makes sense for your program\n\ |
1424 to go on.\n\ | |
5781 | 1425 \n\ |
1426 The optional message identifier allows users to enable or disable\n\ | |
15524
15628a84a4fa
Document form of warning IDs is NAMESPACE:WARNING-NAME (bug #37559)
Rik <rik@octave.org>
parents:
15466
diff
changeset
|
1427 warnings tagged by @var{id}. A message identifier is of the form\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1428 \"NAMESPACE:WARNING-NAME\". Octave's own warnings use the @qcode{\"Octave\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1429 namespace (@pxref{XREFwarning_ids}). The special identifier @qcode{\"all\"}\n\ |
15524
15628a84a4fa
Document form of warning IDs is NAMESPACE:WARNING-NAME (bug #37559)
Rik <rik@octave.org>
parents:
15466
diff
changeset
|
1430 may be used to set the state of all warnings.\n\ |
5781 | 1431 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1432 If the first argument is @qcode{\"on\"} or @qcode{\"off\"},\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1433 set the state of a particular warning using the identifier @var{id}. If the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1434 first argument is @qcode{\"query\"}, query the state of this warning\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1435 instead. If the identifier is omitted, a value of @qcode{\"all\"} is\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1436 assumed. If you set the state of a warning to @qcode{\"error\"}, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1437 warning named by @var{id} is handled as if it were an error instead. So,\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1438 for example, the following handles all warnings as errors:\n\ |
14072
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1439 \n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1440 @example\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1441 @group\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1442 warning (\"error\");\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1443 @end group\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1444 @end example\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1445 \n\ |
18128
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1446 If the state is @qcode{\"on\"} or @qcode{\"off\"} and the third argument\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1447 is @qcode{\"backtrace\"}, then a stack trace is printed along with the\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1448 warning message when warnings occur inside function calls. This option\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1449 is enabled by default.\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1450 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1451 If the state is @qcode{\"on\"}, @qcode{\"off\"}, or @qcode{\"error\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1452 and the third argument is @qcode{\"local\"}, then the warning state\n\ |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1453 will be set temporarily, until the end of the current function.\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1454 Changes to warning states that are set locally affect the current\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1455 function and all functions called from the current scope. The\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1456 previous warning state is restored on return from the current\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1457 function. The @qcode{\"local\"} option is ignored if used in the top-level\n\ |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1458 workspace.\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1459 \n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1460 Implementation Note: For compatibility with @sc{matlab}, escape\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1461 sequences in @var{template} (e.g., @qcode{\"@xbackslashchar{}n\"} =>\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1462 newline) are processed regardless of whether @var{template} has been defined\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1463 with single quotes, as long as there are two or more input arguments. To\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1464 disable escape sequence expansion use a second backslash before the sequence\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1465 (e.g., @qcode{\"@xbackslashchar{}@xbackslashchar{}n\"}) or use the\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1466 @code{regexptranslate} function.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1467 @seealso{warning_ids, lastwarn, error}\n\ |
3373 | 1468 @end deftypefn") |
1489 | 1469 { |
5567 | 1470 octave_value retval; |
3934 | 1471 |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1472 int argc = args.length () + 1; |
3934 | 1473 |
3935 | 1474 bool done = false; |
3934 | 1475 |
5567 | 1476 if (argc > 1 && args.all_strings_p ()) |
3935 | 1477 { |
1478 string_vector argv = args.make_argv ("warning"); | |
1479 | |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1480 std::string arg1 = argv(1); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1481 std::string arg2 = "all"; |
5567 | 1482 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1483 if (argc >= 3) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1484 arg2 = argv(2); |
5567 | 1485 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1486 if (arg1 == "on" || arg1 == "off" || arg1 == "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1487 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1488 octave_map old_warning_options = warning_options; |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1489 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1490 if (argc == 4 && argv(3) == "local" |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1491 && ! symbol_table::at_top_level ()) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1492 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1493 symbol_table::scope_id scope |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1494 = octave_call_stack::current_scope (); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1495 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1496 symbol_table::context_id context |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1497 = octave_call_stack::current_context (); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1498 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1499 octave_scalar_map val = warning_query (arg2); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1500 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1501 octave_value curr_state = val.contents ("state"); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1502 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1503 // FIXME: this might be better with a dictionary object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1504 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1505 octave_value curr_warning_states |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1506 = symbol_table::varval (".saved_warning_states.", |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1507 scope, context); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1508 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1509 octave_map m; |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1510 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1511 if (curr_warning_states.is_defined ()) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1512 m = curr_warning_states.map_value (); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1513 else |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1514 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1515 string_vector fields (2); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1516 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1517 fields(0) = "identifier"; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1518 fields(1) = "state"; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1519 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1520 m = octave_map (dim_vector (0, 1), fields); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1521 } |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1522 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1523 Cell ids = m.contents ("identifier"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1524 Cell states = m.contents ("state"); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1525 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1526 octave_idx_type nel = states.numel (); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1527 bool found = false; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1528 octave_idx_type i; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1529 for (i = 0; i < nel; i++) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1530 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1531 std::string id = ids(i).string_value (); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1532 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1533 if (id == arg2) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1534 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1535 states(i) = curr_state; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1536 found = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1537 break; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1538 } |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1539 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1540 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1541 if (! found) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1542 { |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1543 m.resize (dim_vector (nel+1, 1)); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1544 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1545 ids.resize (dim_vector (nel+1, 1)); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1546 states.resize (dim_vector (nel+1, 1)); |
3934 | 1547 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1548 ids(nel) = arg2; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1549 states(nel) = curr_state; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1550 } |
7202 | 1551 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1552 m.contents ("identifier") = ids; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1553 m.contents ("state") = states; |
7202 | 1554 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1555 symbol_table::assign |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1556 (".saved_warning_states.", m, scope, context); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1557 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1558 // Now ignore the "local" argument and continue to |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1559 // handle the current setting. |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1560 argc--; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1561 } |
7202 | 1562 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1563 if (arg2 == "all") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1564 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1565 octave_map tmp; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1566 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1567 Cell id (1, 1); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1568 Cell st (1, 1); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1569 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1570 id(0) = arg2; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1571 st(0) = arg1; |
7206 | 1572 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1573 // Since internal Octave functions are not |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1574 // compatible, turning all warnings into errors |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1575 // should leave the state of |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1576 // Octave:language-extension alone. |
7202 | 1577 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1578 if (arg1 == "error" |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1579 && warning_options.contains ("identifier")) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1580 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1581 octave_idx_type n = 1; |
7202 | 1582 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1583 Cell tid = warning_options.contents ("identifier"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1584 Cell tst = warning_options.contents ("state"); |
7202 | 1585 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1586 for (octave_idx_type i = 0; i < tid.numel (); i++) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1587 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1588 octave_value vid = tid(i); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1589 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1590 if (vid.is_string ()) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1591 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1592 std::string key = vid.string_value (); |
7202 | 1593 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1594 if (key == "Octave:language-extension" |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1595 || key == "Octave:single-quote-string") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1596 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1597 id.resize (dim_vector (1, n+1)); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1598 st.resize (dim_vector (1, n+1)); |
7206 | 1599 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1600 id(n) = tid(i); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1601 st(n) = tst(i); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1602 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1603 n++; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1604 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1605 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1606 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1607 } |
5567 | 1608 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1609 tmp.assign ("identifier", id); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1610 tmp.assign ("state", st); |
5582 | 1611 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1612 warning_options = tmp; |
5567 | 1613 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1614 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1615 } |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1616 else if (arg2 == "backtrace") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1617 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1618 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1619 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1620 Vbacktrace_on_warning = (arg1 == "on"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1621 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1622 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1623 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1624 else if (arg2 == "debug") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1625 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1626 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1627 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1628 Vdebug_on_warning = (arg1 == "on"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1629 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1630 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1631 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1632 else if (arg2 == "verbose") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1633 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1634 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1635 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1636 Vverbose_warning = (arg1 == "on"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1637 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1638 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1639 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1640 else if (arg2 == "quiet") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1641 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1642 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1643 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1644 Vquiet_warning = (arg1 == "on"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1645 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1646 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1647 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1648 else |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1649 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1650 if (arg2 == "last") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1651 arg2 = Vlast_warning_id; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1652 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1653 set_warning_option (arg1, arg2); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1654 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1655 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1656 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1657 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1658 if (done && nargout > 0) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1659 retval = old_warning_options; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1660 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1661 else if (arg1 == "query") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1662 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1663 if (arg2 == "all") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1664 retval = warning_options; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1665 else if (arg2 == "backtrace" || arg2 == "debug" |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1666 || arg2 == "verbose" || arg2 == "quiet") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1667 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1668 octave_scalar_map tmp; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1669 tmp.assign ("identifier", arg2); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1670 if (arg2 == "backtrace") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1671 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1672 else if (arg2 == "debug") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1673 tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1674 else if (arg2 == "verbose") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1675 tmp.assign ("state", Vverbose_warning ? "on" : "off"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1676 else |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1677 tmp.assign ("state", Vquiet_warning ? "on" : "off"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1678 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1679 retval = tmp; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1680 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1681 else |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1682 retval = warning_query (arg2); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1683 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1684 done = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1685 } |
3934 | 1686 } |
5567 | 1687 else if (argc == 1) |
1688 { | |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1689 if (nargout > 0) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1690 retval = warning_options; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1691 else |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1692 display_warning_options (octave_stdout); |
3934 | 1693 |
5567 | 1694 done = true; |
1695 } | |
1696 else if (argc == 2) | |
1697 { | |
1698 octave_value arg = args(0); | |
1699 | |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1700 octave_map old_warning_options = warning_options; |
5567 | 1701 |
1702 if (arg.is_map ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1703 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1704 octave_map m = arg.map_value (); |
5567 | 1705 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1706 if (m.contains ("identifier") && m.contains ("state")) |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1707 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1708 // Simply step through the struct elements one at a time. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1709 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1710 Cell ident = m.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1711 Cell state = m.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1712 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1713 octave_idx_type nel = ident.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1714 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1715 for (octave_idx_type i = 0; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1716 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1717 std::string tst = state(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1718 std::string tid = ident(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1719 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1720 set_warning_option (tst, tid); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1721 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1722 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1723 else |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20678
diff
changeset
|
1724 error ("warning: STATE structure must have fields 'identifier' and 'state'"); |
5567 | 1725 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1726 done = true; |
5567 | 1727 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1728 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1729 retval = old_warning_options; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1730 } |
5567 | 1731 } |
1732 | |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1733 if (! done) |
3935 | 1734 { |
5567 | 1735 octave_value_list nargs = args; |
1736 | |
1737 std::string id; | |
1738 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1739 bool have_fmt = maybe_extract_message_id ("warning", args, nargs, id); |
5567 | 1740 |
3935 | 1741 std::string prev_msg = Vlast_warning_message; |
1742 | |
5567 | 1743 std::string curr_msg = handle_message (warning_with_id, id.c_str (), |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1744 "unspecified warning", nargs, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1745 have_fmt); |
3935 | 1746 |
1747 if (nargout > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1748 retval = prev_msg; |
3935 | 1749 } |
1750 | |
3934 | 1751 return retval; |
1752 } | |
1753 | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1754 octave_value_list |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1755 set_warning_state (const std::string& id, const std::string& state) |
5794 | 1756 { |
1757 octave_value_list args; | |
1758 | |
1759 args(1) = id; | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1760 args(0) = state; |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1761 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1762 return Fwarning (args, 1); |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1763 } |
5794 | 1764 |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1765 octave_value_list |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1766 set_warning_state (const octave_value_list& args) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1767 { |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1768 return Fwarning (args, 1); |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1769 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1770 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1771 void |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1772 disable_warning (const std::string& id) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1773 { |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1774 set_warning_option ("off", id); |
5794 | 1775 } |
1776 | |
1777 void | |
1778 initialize_default_warning_state (void) | |
1779 { | |
1780 initialize_warning_options ("on"); | |
1781 | |
1782 // Most people will want to have the following disabled. | |
1783 | |
1784 disable_warning ("Octave:array-to-scalar"); | |
1785 disable_warning ("Octave:array-to-vector"); | |
1786 disable_warning ("Octave:imag-to-real"); | |
19852
e9a0bd0b125c
Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents:
19849
diff
changeset
|
1787 disable_warning ("Octave:language-extension"); |
5794 | 1788 disable_warning ("Octave:missing-semicolon"); |
1789 disable_warning ("Octave:neg-dim-as-zero"); | |
1790 disable_warning ("Octave:resize-on-range-error"); | |
1791 disable_warning ("Octave:separator-insert"); | |
1792 disable_warning ("Octave:single-quote-string"); | |
1793 disable_warning ("Octave:str-to-num"); | |
13841
0a158dbdb04a
Remove 3 unused warning ids
Rik <octave@nomad.inbox5.com>
parents:
13709
diff
changeset
|
1794 disable_warning ("Octave:mixed-string-concat"); |
5794 | 1795 disable_warning ("Octave:variable-switch-label"); |
1796 } | |
1797 | |
6361 | 1798 DEFUN (lasterror, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1799 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
1800 @deftypefn {Built-in Function} {@var{lasterr} =} lasterror ()\n\ |
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
1801 @deftypefnx {Built-in Function} {} lasterror (@var{err})\n\ |
14361
8de863b7126b
doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1802 @deftypefnx {Built-in Function} {} lasterror (\"reset\")\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1803 Query or set the last error message structure.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1804 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1805 When called without arguments, return a structure containing the last error\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1806 message and other information related to this error. The elements of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1807 structure are:\n\ |
6361 | 1808 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1809 @table @code\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1810 @item message\n\ |
6361 | 1811 The text of the last error message\n\ |
10840 | 1812 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1813 @item identifier\n\ |
6361 | 1814 The message identifier of this error message\n\ |
10840 | 1815 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1816 @item stack\n\ |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1817 A structure containing information on where the message occurred. This may\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1818 be an empty structure if the information cannot be obtained. The fields of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1819 the structure are:\n\ |
6361 | 1820 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1821 @table @code\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1822 @item file\n\ |
6361 | 1823 The name of the file where the error occurred\n\ |
10840 | 1824 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1825 @item name\n\ |
7001 | 1826 The name of function in which the error occurred\n\ |
10840 | 1827 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1828 @item line\n\ |
7001 | 1829 The line number at which the error occurred\n\ |
10840 | 1830 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1831 @item column\n\ |
6361 | 1832 An optional field with the column number at which the error occurred\n\ |
1833 @end table\n\ | |
1834 @end table\n\ | |
1835 \n\ | |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1836 The last error structure may be set by passing a scalar structure, @var{err},\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1837 as input. Any fields of @var{err} that match those above are set while any\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1838 unspecified fields are initialized with default values.\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1839 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1840 If @code{lasterror} is called with the argument @qcode{\"reset\"}, all\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1841 fields are set to their default values.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1842 @seealso{lasterr, error, lastwarn}\n\ |
6361 | 1843 @end deftypefn") |
1844 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
1845 int nargin = args.length (); |
6361 | 1846 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1847 if (nargin > 1) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1848 print_usage (); |
6361 | 1849 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1850 octave_scalar_map err; |
6361 | 1851 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1852 err.assign ("message", Vlast_error_message); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1853 err.assign ("identifier", Vlast_error_id); |
6361 | 1854 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1855 err.assign ("stack", octave_value (Vlast_error_stack)); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1856 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1857 if (nargin == 1) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1858 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1859 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1860 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1861 if (args(0).string_value () == "reset") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1862 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1863 Vlast_error_message = std::string (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1864 Vlast_error_id = std::string (); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1865 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1866 Vlast_error_stack = initialize_last_error_stack (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1867 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1868 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1869 error ("lasterror: unrecognized string argument"); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1870 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1871 else if (args(0).is_map ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1872 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1873 octave_scalar_map new_err = args(0).scalar_map_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1874 octave_scalar_map new_err_stack; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1875 std::string new_error_message; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1876 std::string new_error_id; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1877 std::string new_error_file; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1878 std::string new_error_name; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1879 int new_error_line = -1; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1880 int new_error_column = -1; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1881 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1882 if (new_err.contains ("message")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1883 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1884 const std::string tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1885 new_err.getfield ("message").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1886 new_error_message = tmp; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1887 } |
6361 | 1888 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1889 if (new_err.contains ("identifier")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1890 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1891 const std::string tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1892 new_err.getfield ("identifier").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1893 new_error_id = tmp; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1894 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1895 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1896 if (new_err.contains ("stack")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1897 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1898 new_err_stack = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1899 new_err.getfield ("stack").scalar_map_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1900 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1901 if (new_err_stack.contains ("file")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1902 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1903 const std::string tmp = |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1904 new_err_stack.getfield ("file").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1905 new_error_file = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1906 } |
6361 | 1907 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1908 if (new_err_stack.contains ("name")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1909 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1910 const std::string tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1911 new_err_stack.getfield ("name").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1912 new_error_name = tmp; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1913 } |
6361 | 1914 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1915 if (new_err_stack.contains ("line")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1916 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1917 const int tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1918 new_err_stack.getfield ("line").nint_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1919 new_error_line = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1920 } |
6361 | 1921 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1922 if (new_err_stack.contains ("column")) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1923 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1924 const int tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1925 new_err_stack.getfield ("column").nint_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1926 new_error_column = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1927 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1928 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1929 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1930 Vlast_error_message = new_error_message; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1931 Vlast_error_id = new_error_id; |
6361 | 1932 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1933 if (new_err.contains ("stack")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1934 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1935 new_err_stack.setfield ("file", new_error_file); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1936 new_err_stack.setfield ("name", new_error_name); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1937 new_err_stack.setfield ("line", new_error_line); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1938 new_err_stack.setfield ("column", new_error_column); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1939 Vlast_error_stack = new_err_stack; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1940 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1941 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1942 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1943 // No stack field. Fill it in with backtrace info. |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1944 octave_idx_type curr_frame = -1; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1945 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1946 Vlast_error_stack |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1947 = octave_call_stack::backtrace (0, curr_frame); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1948 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1949 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1950 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1951 error ("lasterror: argument must be a structure or a string"); |
6361 | 1952 } |
1953 | |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1954 return octave_value (err); |
6361 | 1955 } |
1956 | |
5567 | 1957 DEFUN (lasterr, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1958 "-*- texinfo -*-\n\ |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1959 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lasterr ()\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1960 @deftypefnx {Built-in Function} {} lasterr (@var{msg})\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1961 @deftypefnx {Built-in Function} {} lasterr (@var{msg}, @var{msgid})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1962 Query or set the last error message.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1963 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1964 When called without input arguments, return the last error message and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1965 message identifier.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1966 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1967 With one argument, set the last error message to @var{msg}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1968 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
1969 With two arguments, also set the last message identifier.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1970 @seealso{lasterror, error, lastwarn}\n\ |
3935 | 1971 @end deftypefn") |
1972 { | |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
1973 int nargin = args.length (); |
3935 | 1974 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
1975 if (nargin > 2) |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1976 print_usage (); |
3935 | 1977 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1978 string_vector argv = args.make_argv ("lasterr"); |
5567 | 1979 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1980 std::string prev_error_id = Vlast_error_id; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1981 std::string prev_error_message = Vlast_error_message; |
5567 | 1982 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
1983 if (nargin == 2) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1984 { |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1985 Vlast_error_id = argv(2); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1986 Vlast_error_message = argv(1); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1987 } |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1988 else if (nargin == 1) |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1989 { |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1990 Vlast_error_id = ""; |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1991 Vlast_error_message = argv(1); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1992 } |
5567 | 1993 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
1994 if (nargin == 0 || nargout > 0) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1995 return ovl (prev_error_message, prev_error_id); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1996 else |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
1997 return octave_value_list (); |
3935 | 1998 } |
1999 | |
5567 | 2000 DEFUN (lastwarn, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2001 "-*- texinfo -*-\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
2002 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lastwarn ()\n\ |
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
2003 @deftypefnx {Built-in Function} {} lastwarn (@var{msg})\n\ |
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
2004 @deftypefnx {Built-in Function} {} lastwarn (@var{msg}, @var{msgid})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2005 Query or set the last warning message.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2006 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2007 When called without input arguments, return the last warning message and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2008 message identifier.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2009 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2010 With one argument, set the last warning message to @var{msg}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2011 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2012 With two arguments, also set the last message identifier.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
2013 @seealso{warning, lasterror, lasterr}\n\ |
3934 | 2014 @end deftypefn") |
2015 { | |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2016 int nargin = args.length (); |
3934 | 2017 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2018 if (nargin > 2) |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2019 print_usage (); |
5567 | 2020 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2021 string_vector argv = args.make_argv ("lastwarn"); |
5567 | 2022 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2023 std::string prev_warning_id = Vlast_warning_id; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2024 std::string prev_warning_message = Vlast_warning_message; |
3934 | 2025 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2026 if (nargin == 2) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2027 { |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2028 Vlast_warning_id = argv(2); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2029 Vlast_warning_message = argv(1); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2030 } |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2031 else if (nargin == 1) |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2032 { |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2033 Vlast_warning_id = ""; |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2034 Vlast_warning_message = argv(1); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2035 } |
5567 | 2036 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2037 if (nargin == 0 || nargout > 0) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2038 return ovl (prev_warning_message, prev_warning_id); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2039 else |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2040 return octave_value_list (); |
897 | 2041 } |
2042 | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2043 /* FIXME: Deprecated in 4.0 and scheduled for removal in 4.4 */ |
19111 | 2044 DEFUN (__usage__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2045 "-*- texinfo -*-\n\ |
3373 | 2046 @deftypefn {Built-in Function} {} usage (@var{msg})\n\ |
2047 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\ | |
2048 set Octave's internal error state such that control will return to the\n\ | |
2049 top level without evaluating any more commands. This is useful for\n\ | |
2050 aborting from functions.\n\ | |
2051 \n\ | |
2052 After @code{usage} is evaluated, Octave will print a traceback of all\n\ | |
2053 the function calls leading to the usage message.\n\ | |
899 | 2054 \n\ |
3373 | 2055 You should use this function for reporting problems errors that result\n\ |
2056 from an improper call to a function, such as calling a function with an\n\ | |
2057 incorrect number of arguments, or with arguments of the wrong type. For\n\ | |
2058 example, most functions distributed with Octave begin with code like\n\ | |
2059 this\n\ | |
2060 \n\ | |
2061 @example\n\ | |
2062 @group\n\ | |
2063 if (nargin != 2)\n\ | |
2064 usage (\"foo (a, b)\");\n\ | |
2065 endif\n\ | |
2066 @end group\n\ | |
2067 @end example\n\ | |
2068 \n\ | |
2069 @noindent\n\ | |
2070 to check for the proper number of arguments.\n\ | |
2071 @end deftypefn") | |
899 | 2072 { |
3934 | 2073 octave_value_list retval; |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
2074 handle_message (usage_with_id, "", "unknown", args, true); |
3934 | 2075 return retval; |
899 | 2076 } |
2077 | |
5794 | 2078 DEFUN (beep_on_error, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2079 "-*- texinfo -*-\n\ |
10840 | 2080 @deftypefn {Built-in Function} {@var{val} =} beep_on_error ()\n\ |
5794 | 2081 @deftypefnx {Built-in Function} {@var{old_val} =} beep_on_error (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2082 @deftypefnx {Built-in Function} {} beep_on_error (@var{new_val}, \"local\")\n\ |
5794 | 2083 Query or set the internal variable that controls whether Octave will try\n\ |
2084 to ring the terminal bell before printing an error message.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2085 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2086 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2087 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2088 The original variable value is restored when exiting the function.\n\ |
5794 | 2089 @end deftypefn") |
3707 | 2090 { |
5794 | 2091 return SET_INTERNAL_VARIABLE (beep_on_error); |
3707 | 2092 } |
2093 | |
5794 | 2094 DEFUN (debug_on_error, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2095 "-*- texinfo -*-\n\ |
10840 | 2096 @deftypefn {Built-in Function} {@var{val} =} debug_on_error ()\n\ |
5794 | 2097 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_error (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2098 @deftypefnx {Built-in Function} {} debug_on_error (@var{new_val}, \"local\")\n\ |
5794 | 2099 Query or set the internal variable that controls whether Octave will try\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2100 to enter the debugger when an error is encountered.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2101 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2102 This will also inhibit printing of the normal traceback message (you will\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2103 only see the top-level error message).\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2104 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2105 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2106 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2107 The original variable value is restored when exiting the function.\n\ |
15573
63d024333bee
doc: Add seealso links between debug_on_XXX functions (bug #37576)
Rik <rik@octave.org>
parents:
15524
diff
changeset
|
2108 @seealso{debug_on_warning, debug_on_interrupt}\n\ |
5794 | 2109 @end deftypefn") |
2110 { | |
2111 return SET_INTERNAL_VARIABLE (debug_on_error); | |
2112 } | |
3707 | 2113 |
5794 | 2114 DEFUN (debug_on_warning, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2115 "-*- texinfo -*-\n\ |
10840 | 2116 @deftypefn {Built-in Function} {@var{val} =} debug_on_warning ()\n\ |
5794 | 2117 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_warning (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2118 @deftypefnx {Built-in Function} {} debug_on_warning (@var{new_val}, \"local\")\n\ |
5794 | 2119 Query or set the internal variable that controls whether Octave will try\n\ |
2120 to enter the debugger when a warning is encountered.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2121 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2122 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20140
diff
changeset
|
2123 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2124 The original variable value is restored when exiting the function.\n\ |
15573
63d024333bee
doc: Add seealso links between debug_on_XXX functions (bug #37576)
Rik <rik@octave.org>
parents:
15524
diff
changeset
|
2125 @seealso{debug_on_error, debug_on_interrupt}\n\ |
5794 | 2126 @end deftypefn") |
2127 { | |
2128 return SET_INTERNAL_VARIABLE (debug_on_warning); | |
2174 | 2129 } |
2130 | |
7977
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2131 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2132 last_error_message (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2133 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2134 return Vlast_error_message; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2135 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2136 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2137 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2138 last_error_id (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2139 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2140 return Vlast_error_id; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2141 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2142 |
18222
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2143 octave_map |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2144 last_error_stack (void) |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2145 { |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2146 return Vlast_error_stack; |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2147 } |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2148 |
7977
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2149 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2150 last_warning_message (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2151 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2152 return Vlast_warning_message; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2153 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2154 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2155 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2156 last_warning_id (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2157 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2158 return Vlast_warning_id; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2159 } |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2160 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2161 void |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2162 interpreter_try (unwind_protect& frame) |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2163 { |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2164 frame.protect_var (buffer_error_messages); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2165 frame.protect_var (Vdebug_on_error); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2166 frame.protect_var (Vdebug_on_warning); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2167 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2168 buffer_error_messages++; |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2169 Vdebug_on_error = false; |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2170 Vdebug_on_warning = false; |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2171 } |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2172 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2173 |