Mercurial > hg > octave-lyh
annotate src/error.cc @ 9753:892e2aa7bc75
improve error messages by auto-prepending current function name
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 22 Oct 2009 08:56:58 +0200 |
parents | ef45d191d833 |
children | 2cd940306a06 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8920 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
1343 | 28 #include <cstdarg> |
1633 | 29 #include <cstring> |
1343 | 30 |
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" |
44 #include "pt-pr-code.h" | |
45 #include "pt-stmt.h" | |
46 #include "toplev.h" | |
47 #include "unwind-prot.h" | |
2370 | 48 #include "variables.h" |
1 | 49 |
2174 | 50 // TRUE means that Octave will try to beep obnoxiously before printing |
51 // error messages. | |
5794 | 52 static bool Vbeep_on_error = false; |
2174 | 53 |
3707 | 54 // TRUE means that Octave will try to enter the debugger when an error |
55 // is encountered. This will also inhibit printing of the normal | |
56 // traceback message (you will only see the top-level error message). | |
7353 | 57 bool Vdebug_on_error = false; |
3707 | 58 |
59 // TRUE means that Octave will try to enter the debugger when a warning | |
60 // is encountered. | |
7353 | 61 bool Vdebug_on_warning = false; |
3707 | 62 |
5567 | 63 // TRUE means that Octave will try to display a stack trace when a |
64 // warning is encountered. | |
65 static bool Vbacktrace_on_warning = false; | |
66 | |
67 // TRUE means that Octave will print a verbose warning. Currently unused. | |
68 static bool Vverbose_warning; | |
69 | |
5582 | 70 // TRUE means that Octave will print no warnings, but lastwarn will be |
71 //updated | |
72 static bool Vquiet_warning = false; | |
73 | |
5567 | 74 // A structure containing (most of) the current state of warnings. |
75 static Octave_map warning_options; | |
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 |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
90 static Octave_map Vlast_error_stack; |
6361 | 91 |
143 | 92 // Current error state. |
3935 | 93 // |
94 // Valid values: | |
95 // | |
96 // -2: an error has occurred, but don't print any messages. | |
97 // -1: an error has occurred, we are printing a traceback | |
98 // 0: no error | |
99 // 1: an error has occurred | |
100 // | |
672 | 101 int error_state = 0; |
102 | |
3489 | 103 // Current warning state. |
3935 | 104 // |
105 // Valid values: | |
106 // | |
107 // 0: no warning | |
108 // 1: a warning has occurred | |
109 // | |
3489 | 110 int warning_state = 0; |
111 | |
1489 | 112 // Tell the error handler whether to print messages, or just store |
113 // them for later. Used for handling errors in eval() and | |
114 // the `unwind_protect' statement. | |
4699 | 115 int buffer_error_messages = 0; |
1489 | 116 |
3815 | 117 // TRUE means error messages are turned off. |
118 bool discard_error_messages = false; | |
119 | |
4452 | 120 // TRUE means warning messages are turned off. |
121 bool discard_warning_messages = false; | |
122 | |
3811 | 123 // The message buffer. |
5765 | 124 static std::ostringstream *error_message_buffer = 0; |
143 | 125 |
4318 | 126 void |
127 reset_error_handler (void) | |
128 { | |
129 error_state = 0; | |
130 warning_state = 0; | |
4699 | 131 buffer_error_messages = 0; |
4318 | 132 discard_error_messages = false; |
133 } | |
134 | |
5567 | 135 static void |
5794 | 136 initialize_warning_options (const std::string& state) |
5567 | 137 { |
138 warning_options.clear (); | |
139 | |
140 warning_options.assign ("identifier", "all"); | |
141 warning_options.assign ("state", state); | |
142 } | |
143 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
144 static Octave_map |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
145 initialize_last_error_stack (void) |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
146 { |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
147 static bool initialized = false; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
148 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
149 static string_vector sv (4); |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
150 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
151 if (! initialized) |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
152 { |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
153 sv[0] = "file"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
154 sv[1] = "name"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
155 sv[2] = "line"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
156 sv[3] = "column"; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
157 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
158 initialized = true; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
159 } |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
160 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
161 return Octave_map (dim_vector (0, 1), sv); |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
162 } |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
163 |
3491 | 164 // Warning messages are never buffered. |
165 | |
166 static void | |
5567 | 167 vwarning (const char *name, const char *id, const char *fmt, va_list args) |
3491 | 168 { |
4452 | 169 if (discard_warning_messages) |
170 return; | |
171 | |
3491 | 172 flush_octave_stdout (); |
173 | |
5765 | 174 std::ostringstream output_buf; |
3491 | 175 |
176 if (name) | |
3761 | 177 output_buf << name << ": "; |
178 | |
179 octave_vformat (output_buf, fmt, args); | |
180 | |
5765 | 181 output_buf << std::endl; |
3491 | 182 |
5775 | 183 // FIXME -- we really want to capture the message before it |
3935 | 184 // has all the formatting goop attached to it. We probably also |
185 // want just the message, not the traceback information. | |
186 | |
5765 | 187 std::string msg_string = output_buf.str (); |
3934 | 188 |
3935 | 189 if (! warning_state) |
190 { | |
191 // This is the first warning in a possible series. | |
5567 | 192 |
193 Vlast_warning_id = id; | |
3935 | 194 Vlast_warning_message = msg_string; |
195 } | |
3934 | 196 |
5582 | 197 if (! Vquiet_warning) |
198 { | |
199 octave_diary << msg_string; | |
3935 | 200 |
5582 | 201 std::cerr << msg_string; |
202 } | |
3491 | 203 } |
204 | |
1 | 205 static void |
4732 | 206 verror (bool save_last_error, std::ostream& os, |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
207 const char *name, 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
|
208 bool with_cfn = false) |
1 | 209 { |
3815 | 210 if (discard_error_messages) |
211 return; | |
212 | |
3585 | 213 if (! buffer_error_messages) |
214 flush_octave_stdout (); | |
914 | 215 |
5775 | 216 // FIXME -- we really want to capture the message before it |
3935 | 217 // has all the formatting goop attached to it. We probably also |
218 // want just the message, not the traceback information. | |
219 | |
7877 | 220 std::ostringstream output_buf; |
221 | |
222 octave_vformat (output_buf, fmt, args); | |
223 | |
224 std::string base_msg = output_buf.str (); | |
225 | |
226 bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; | |
227 | |
228 std::string msg_string; | |
229 | |
230 if (to_beep_or_not_to_beep_p) | |
231 msg_string = "\a"; | |
232 | |
233 if (name) | |
234 msg_string += std::string (name) + ": "; | |
235 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
236 // 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
|
237 // 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
|
238 // 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
|
239 // 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
|
240 if (with_cfn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
241 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
242 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
|
243 if (curfcn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
244 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
245 std::string cfn = curfcn->name (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
246 if (! cfn.empty ()) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
247 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
248 cfn += ':'; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
249 if (cfn.length () > base_msg.length () |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
250 || base_msg.compare (0, cfn.length (), cfn) != 0) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
251 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
252 msg_string += cfn + ' '; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
253 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
254 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
255 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
256 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
257 |
7880 | 258 msg_string += base_msg + "\n"; |
3935 | 259 |
4731 | 260 if (! error_state && save_last_error) |
3935 | 261 { |
262 // This is the first error in a possible series. | |
5567 | 263 |
264 Vlast_error_id = id; | |
7877 | 265 Vlast_error_message = base_msg; |
6361 | 266 |
7877 | 267 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
6361 | 268 |
7877 | 269 if (fcn) |
270 { | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
271 octave_idx_type curr_frame = -1; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
272 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
273 Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame); |
6361 | 274 } |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
275 else |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
276 Vlast_error_stack = initialize_last_error_stack (); |
3935 | 277 } |
278 | |
1489 | 279 if (buffer_error_messages) |
280 { | |
7882 | 281 if (error_message_buffer) |
282 msg_string = "error: " + msg_string; | |
283 else | |
7880 | 284 error_message_buffer = new std::ostringstream (); |
1489 | 285 |
7880 | 286 *error_message_buffer << msg_string; |
1489 | 287 } |
288 else | |
289 { | |
3935 | 290 octave_diary << msg_string; |
4732 | 291 os << msg_string; |
1489 | 292 } |
1 | 293 } |
294 | |
1266 | 295 // Note that we don't actually print any message if the error string |
296 // is just "" or "\n". This allows error ("") and error ("\n") to | |
297 // just set the error state. | |
298 | |
1005 | 299 static void |
5567 | 300 error_1 (std::ostream& os, const char *name, const char *id, |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
301 const char *fmt, va_list args, bool with_cfn = false) |
1005 | 302 { |
303 if (error_state != -2) | |
304 { | |
1489 | 305 if (fmt) |
1005 | 306 { |
1489 | 307 if (*fmt) |
1005 | 308 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
309 size_t len = strlen (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
310 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
311 if (len > 0) |
1266 | 312 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
313 if (fmt[len - 1] == '\n') |
1266 | 314 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
315 if (len > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
316 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
317 char *tmp_fmt = strsave (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
318 tmp_fmt[len - 1] = '\0'; |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
319 verror (true, os, name, id, tmp_fmt, args, with_cfn); |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
320 delete [] tmp_fmt; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
321 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
322 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
323 error_state = -2; |
1489 | 324 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
325 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
326 { |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
327 verror (true, os, name, id, fmt, args, with_cfn); |
1423 | 328 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
329 if (! error_state) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
330 error_state = 1; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
331 } |
1266 | 332 } |
1005 | 333 } |
334 } | |
1489 | 335 else |
336 panic ("error_1: invalid format"); | |
1005 | 337 } |
338 } | |
339 | |
1 | 340 void |
6338 | 341 vmessage (const char *name, const char *fmt, va_list args) |
342 { | |
343 verror (false, std::cerr, name, "", fmt, args); | |
344 } | |
345 | |
346 void | |
1 | 347 message (const char *name, const char *fmt, ...) |
348 { | |
349 va_list args; | |
350 va_start (args, fmt); | |
6338 | 351 vmessage (name, fmt, args); |
1 | 352 va_end (args); |
353 } | |
354 | |
355 void | |
6338 | 356 vmessage_with_id (const char *name, const char *id, const char *fmt, |
357 va_list args) | |
358 { | |
359 verror (false, std::cerr, name, id, fmt, args); | |
360 } | |
361 | |
362 void | |
5567 | 363 message_with_id (const char *name, const char *id, const char *fmt, ...) |
364 { | |
365 va_list args; | |
366 va_start (args, fmt); | |
6338 | 367 vmessage_with_id (name, id, fmt, args); |
5567 | 368 va_end (args); |
369 } | |
370 | |
371 void | |
372 usage_1 (const char *id, const char *fmt, va_list args) | |
373 { | |
374 verror (true, std::cerr, "usage", id, fmt, args); | |
375 error_state = -1; | |
376 } | |
377 | |
378 void | |
6338 | 379 vusage (const char *fmt, va_list args) |
380 { | |
381 usage_1 ("", fmt, args); | |
382 } | |
383 | |
384 void | |
1 | 385 usage (const char *fmt, ...) |
386 { | |
387 va_list args; | |
388 va_start (args, fmt); | |
6338 | 389 vusage (fmt, args); |
5567 | 390 va_end (args); |
391 } | |
392 | |
393 void | |
6338 | 394 vusage_with_id (const char *id, const char *fmt, va_list args) |
395 { | |
396 usage_1 (id, fmt, args); | |
397 } | |
398 | |
399 void | |
5567 | 400 usage_with_id (const char *id, const char *fmt, ...) |
401 { | |
402 va_list args; | |
403 va_start (args, fmt); | |
6338 | 404 vusage_with_id (id, fmt, args); |
1 | 405 va_end (args); |
406 } | |
407 | |
3707 | 408 static void |
3719 | 409 pr_where_2 (const char *fmt, va_list args) |
410 { | |
411 if (fmt) | |
412 { | |
413 if (*fmt) | |
414 { | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
415 size_t len = strlen (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
416 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
417 if (len > 0) |
3719 | 418 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
419 if (fmt[len - 1] == '\n') |
3719 | 420 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
421 if (len > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
422 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
423 char *tmp_fmt = strsave (fmt); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
424 tmp_fmt[len - 1] = '\0'; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
425 verror (false, std::cerr, 0, "", tmp_fmt, args); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
426 delete [] tmp_fmt; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
427 } |
3719 | 428 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
429 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
430 verror (false, std::cerr, 0, "", fmt, args); |
3719 | 431 } |
432 } | |
433 } | |
434 else | |
435 panic ("pr_where_2: invalid format"); | |
436 } | |
437 | |
438 static void | |
3707 | 439 pr_where_1 (const char *fmt, ...) |
440 { | |
441 va_list args; | |
442 va_start (args, fmt); | |
3719 | 443 pr_where_2 (fmt, args); |
3707 | 444 va_end (args); |
445 } | |
446 | |
447 static void | |
8973 | 448 pr_where (const char *who) |
3707 | 449 { |
8973 | 450 octave_idx_type curr_frame = -1; |
3707 | 451 |
8973 | 452 Octave_map stk = octave_call_stack::backtrace (0, curr_frame); |
4976 | 453 |
8973 | 454 octave_idx_type nframes_to_display = stk.numel (); |
4976 | 455 |
8973 | 456 if (nframes_to_display > 0) |
457 { | |
458 pr_where_1 ("%s: called from\n", who); | |
3708 | 459 |
8973 | 460 Cell names = stk.contents ("name"); |
461 Cell lines = stk.contents ("line"); | |
462 Cell columns = stk.contents ("column"); | |
3707 | 463 |
8973 | 464 for (octave_idx_type i = 0; i < nframes_to_display; i++) |
4976 | 465 { |
8973 | 466 octave_value name = names(i); |
467 octave_value line = lines(i); | |
468 octave_value column = columns(i); | |
3707 | 469 |
8973 | 470 std::string nm = name.string_value (); |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7353
diff
changeset
|
471 |
8973 | 472 pr_where_1 (" %s at line %d column %d\n", nm.c_str (), |
473 line.int_value (), column.int_value ()); | |
4719 | 474 } |
3707 | 475 } |
476 } | |
477 | |
6000 | 478 static void |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
479 error_2 (const char *id, const char *fmt, va_list args, bool with_cfn = false) |
6000 | 480 { |
481 int init_state = error_state; | |
482 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
483 error_1 (std::cerr, "error", id, fmt, args, with_cfn); |
6000 | 484 |
485 if ((interactive || forced_interactive) | |
486 && Vdebug_on_error && init_state == 0 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
487 && octave_call_stack::caller_user_code ()) |
6000 | 488 { |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
489 unwind_protect::protect_var (Vdebug_on_error); |
6000 | 490 Vdebug_on_error = false; |
491 | |
8973 | 492 error_state = 0; |
6000 | 493 |
8973 | 494 pr_where ("error"); |
6000 | 495 |
496 do_keyboard (octave_value_list ()); | |
497 | |
498 unwind_protect::run (); | |
499 } | |
500 } | |
501 | |
502 void | |
6338 | 503 verror (const char *fmt, va_list args) |
504 { | |
505 error_2 ("", fmt, args); | |
506 } | |
507 | |
508 void | |
6000 | 509 error (const char *fmt, ...) |
510 { | |
511 va_list args; | |
512 va_start (args, fmt); | |
6338 | 513 verror (fmt, args); |
6000 | 514 va_end (args); |
515 } | |
516 | |
517 void | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
518 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
|
519 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
520 error_2 ("", fmt, args, true); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
521 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
522 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
523 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
524 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
|
525 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
526 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
527 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
528 verror_with_cfn (fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
529 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
530 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
531 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
532 void |
6338 | 533 verror_with_id (const char *id, const char *fmt, va_list args) |
534 { | |
535 error_2 (id, fmt, args); | |
536 } | |
537 | |
538 void | |
6000 | 539 error_with_id (const char *id, const char *fmt, ...) |
540 { | |
541 va_list args; | |
542 va_start (args, fmt); | |
6338 | 543 verror_with_id (id, fmt, args); |
6000 | 544 va_end (args); |
545 } | |
546 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
547 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
548 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
|
549 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
550 error_2 (id, fmt, args, true); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
551 } |
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 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
554 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
|
555 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
556 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
557 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
558 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
|
559 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
560 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
561 |
5567 | 562 static int |
563 check_state (const std::string& state) | |
564 { | |
565 // -1: not found | |
566 // 0: found, "off" | |
567 // 1: found, "on" | |
568 // 2: found, "error" | |
569 | |
570 if (state == "off") | |
571 return 0; | |
572 else if (state == "on") | |
573 return 1; | |
574 else if (state == "error") | |
575 return 2; | |
576 else | |
577 return -1; | |
578 } | |
579 | |
580 // For given warning ID, return 0 if warnings are disabled, 1 if | |
581 // enabled, and 2 if this ID should be an error instead of a warning. | |
582 | |
5781 | 583 int |
5567 | 584 warning_enabled (const std::string& id) |
1 | 585 { |
5567 | 586 int retval = 0; |
587 | |
588 int all_state = -1; | |
589 int id_state = -1; | |
590 | |
591 octave_idx_type nel = warning_options.numel (); | |
592 | |
593 if (nel > 0) | |
594 { | |
595 Cell identifier = warning_options.contents ("identifier"); | |
596 Cell state = warning_options.contents ("state"); | |
597 | |
598 bool all_found = false; | |
599 bool id_found = false; | |
600 | |
601 for (octave_idx_type i = 0; i < nel; i++) | |
602 { | |
603 octave_value ov = identifier(i); | |
604 std::string ovs = ov.string_value (); | |
605 | |
606 if (! all_found && ovs == "all") | |
607 { | |
608 all_state = check_state (state(i).string_value ()); | |
609 | |
610 if (all_state >= 0) | |
611 all_found = true; | |
612 } | |
613 | |
614 if (! id_found && ovs == id) | |
615 { | |
616 id_state = check_state (state(i).string_value ()); | |
617 | |
618 if (id_state >= 0) | |
619 id_found = true; | |
620 } | |
621 | |
622 if (all_found && id_found) | |
623 break; | |
624 } | |
625 } | |
626 | |
627 if (all_state == -1) | |
628 panic_impossible (); | |
629 | |
630 if (all_state == 0) | |
631 { | |
632 if (id_state >= 0) | |
633 retval = id_state; | |
634 } | |
635 else if (all_state == 1) | |
636 { | |
637 if (id_state == 0 || id_state == 2) | |
638 retval = id_state; | |
639 else | |
640 retval = all_state; | |
641 } | |
642 else if (all_state == 2) | |
7206 | 643 { |
644 if (id_state == 0) | |
645 retval= id_state; | |
646 else | |
647 retval = all_state; | |
648 } | |
5567 | 649 |
650 return retval; | |
651 } | |
652 | |
653 static void | |
654 warning_1 (const char *id, const char *fmt, va_list args) | |
655 { | |
656 int warn_opt = warning_enabled (id); | |
657 | |
658 if (warn_opt == 2) | |
659 { | |
660 // Handle this warning as an error. | |
661 | |
5998 | 662 error_2 (id, fmt, args); |
5567 | 663 } |
664 else if (warn_opt == 1) | |
3934 | 665 { |
8973 | 666 vwarning ("warning", id, fmt, args); |
667 | |
668 if (! symbol_table::at_top_level () | |
5567 | 669 && Vbacktrace_on_warning |
4452 | 670 && ! warning_state |
671 && ! discard_warning_messages) | |
8973 | 672 pr_where ("warning"); |
3707 | 673 |
3935 | 674 warning_state = 1; |
675 | |
3934 | 676 if ((interactive || forced_interactive) |
5743 | 677 && Vdebug_on_warning |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
678 && octave_call_stack::caller_user_code ()) |
3934 | 679 { |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
680 unwind_protect::protect_var (Vdebug_on_warning); |
3934 | 681 Vdebug_on_warning = false; |
3707 | 682 |
3934 | 683 do_keyboard (octave_value_list ()); |
3707 | 684 |
3934 | 685 unwind_protect::run (); |
686 } | |
3707 | 687 } |
1 | 688 } |
689 | |
690 void | |
6338 | 691 vwarning (const char *fmt, va_list args) |
692 { | |
693 warning_1 ("", fmt, args); | |
694 } | |
695 | |
696 void | |
5567 | 697 warning (const char *fmt, ...) |
698 { | |
699 va_list args; | |
700 va_start (args, fmt); | |
6338 | 701 vwarning (fmt, args); |
5567 | 702 va_end (args); |
703 } | |
704 | |
705 void | |
6338 | 706 vwarning_with_id (const char *id, const char *fmt, va_list args) |
707 { | |
708 warning_1 (id, fmt, args); | |
709 } | |
710 | |
711 void | |
5567 | 712 warning_with_id (const char *id, const char *fmt, ...) |
713 { | |
714 va_list args; | |
715 va_start (args, fmt); | |
6338 | 716 vwarning_with_id (id, fmt, args); |
5567 | 717 va_end (args); |
718 } | |
719 | |
720 void | |
6338 | 721 vparse_error (const char *fmt, va_list args) |
722 { | |
723 error_1 (std::cerr, 0, "", fmt, args); | |
724 } | |
725 | |
726 void | |
1005 | 727 parse_error (const char *fmt, ...) |
728 { | |
729 va_list args; | |
730 va_start (args, fmt); | |
6338 | 731 vparse_error (fmt, args); |
5567 | 732 va_end (args); |
733 } | |
734 | |
735 void | |
6338 | 736 vparse_error_with_id (const char *id, const char *fmt, va_list args) |
737 { | |
738 error_1 (std::cerr, 0, id, fmt, args); | |
739 } | |
740 | |
741 void | |
5567 | 742 parse_error_with_id (const char *id, const char *fmt, ...) |
743 { | |
744 va_list args; | |
745 va_start (args, fmt); | |
6338 | 746 vparse_error_with_id (id, fmt, args); |
1 | 747 va_end (args); |
748 } | |
749 | |
189 | 750 void |
6361 | 751 rethrow_error (const char *id, const char *fmt, ...) |
752 { | |
753 va_list args; | |
754 va_start (args, fmt); | |
6640 | 755 error_1 (std::cerr, 0, id, fmt, args); |
6361 | 756 va_end (args); |
757 } | |
758 | |
759 void | |
1 | 760 panic (const char *fmt, ...) |
761 { | |
762 va_list args; | |
763 va_start (args, fmt); | |
4699 | 764 buffer_error_messages = 0; |
3815 | 765 discard_error_messages = false; |
5567 | 766 verror (false, std::cerr, "panic", "", fmt, args); |
1 | 767 va_end (args); |
768 abort (); | |
769 } | |
770 | |
4732 | 771 static void |
772 defun_usage_message_1 (const char *fmt, ...) | |
773 { | |
774 va_list args; | |
775 va_start (args, fmt); | |
5567 | 776 error_1 (octave_stdout, 0, "", fmt, args); |
4732 | 777 va_end (args); |
778 } | |
779 | |
780 void | |
781 defun_usage_message (const std::string& msg) | |
782 { | |
783 defun_usage_message_1 ("%s", msg.c_str ()); | |
784 } | |
785 | |
5567 | 786 typedef void (*error_fun)(const char *, const char *, ...); |
1489 | 787 |
2086 | 788 extern octave_value_list Fsprintf (const octave_value_list&, int); |
1489 | 789 |
3934 | 790 static std::string |
5567 | 791 handle_message (error_fun f, const char *id, const char *msg, |
792 const octave_value_list& args) | |
528 | 793 { |
3934 | 794 std::string retval; |
528 | 795 |
3523 | 796 std::string tstr; |
1728 | 797 |
528 | 798 int nargin = args.length (); |
799 | |
2745 | 800 if (nargin > 0) |
528 | 801 { |
3066 | 802 octave_value arg; |
803 | |
804 if (nargin > 1) | |
805 { | |
806 octave_value_list tmp = Fsprintf (args, 1); | |
807 arg = tmp(0); | |
808 } | |
809 else | |
810 arg = args(0); | |
2745 | 811 |
812 if (arg.is_defined ()) | |
528 | 813 { |
2745 | 814 if (arg.is_string ()) |
815 { | |
816 tstr = arg.string_value (); | |
817 msg = tstr.c_str (); | |
818 | |
819 if (! msg) | |
820 return retval; | |
821 } | |
822 else if (arg.is_empty ()) | |
528 | 823 return retval; |
824 } | |
825 } | |
826 | |
1489 | 827 // Ugh. |
828 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
829 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
|
830 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
831 if (len > 0) |
1489 | 832 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
833 if (msg[len - 1] == '\n') |
1489 | 834 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
835 if (len > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
836 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
837 char *tmp_msg = strsave (msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
838 tmp_msg[len - 1] = '\0'; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
839 f (id, "%s\n", tmp_msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
840 retval = tmp_msg; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
841 delete [] tmp_msg; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
842 } |
1489 | 843 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
844 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
845 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
846 f (id, "%s", msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
847 retval = msg; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
848 } |
3934 | 849 } |
528 | 850 |
851 return retval; | |
852 } | |
853 | |
6361 | 854 DEFUN (rethrow, args, , |
855 "-*- texinfo -*-\n\ | |
856 @deftypefn {Built-in Function} {} rethrow (@var{err})\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
857 Reissues a previous error as defined by @var{err}. @var{err} is a structure\n\ |
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
858 that must contain at least the 'message' and 'identifier' fields. @var{err}\n\ |
6361 | 859 can also contain a field 'stack' that gives information on the assumed\n\ |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
860 location of the error. Typically @var{err} is returned from\n\ |
6361 | 861 @code{lasterror}.\n\ |
862 @seealso{lasterror, lasterr, error}\n\ | |
863 @end deftypefn") | |
864 { | |
865 octave_value retval; | |
866 int nargin = args.length(); | |
867 | |
868 if (nargin != 1) | |
6959 | 869 print_usage (); |
6361 | 870 else |
871 { | |
6483 | 872 Octave_map err = args(0).map_value (); |
6361 | 873 |
6483 | 874 if (! error_state) |
6361 | 875 { |
6483 | 876 if (err.contains ("message") && err.contains ("identifier")) |
6361 | 877 { |
6483 | 878 std::string msg = err.contents("message")(0).string_value (); |
879 std::string id = err.contents("identifier")(0).string_value (); | |
6361 | 880 int len = msg.length(); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
881 |
6361 | 882 std::string file; |
883 std::string nm; | |
884 int l = -1; | |
885 int c = -1; | |
886 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
887 Octave_map err_stack = initialize_last_error_stack (); |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
888 |
6483 | 889 if (err.contains ("stack")) |
6361 | 890 { |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
891 err_stack = err.contents("stack")(0).map_value (); |
6483 | 892 |
6640 | 893 if (err_stack.numel () > 0) |
894 { | |
895 if (err_stack.contains ("file")) | |
896 file = err_stack.contents("file")(0).string_value (); | |
6483 | 897 |
6640 | 898 if (err_stack.contains ("name")) |
899 nm = err_stack.contents("name")(0).string_value (); | |
6483 | 900 |
6640 | 901 if (err_stack.contains ("line")) |
902 l = err_stack.contents("line")(0).nint_value (); | |
903 | |
904 if (err_stack.contains ("column")) | |
905 c = err_stack.contents("column")(0).nint_value (); | |
906 } | |
6361 | 907 } |
908 | |
909 // Ugh. | |
6483 | 910 char *tmp_msg = strsave (msg.c_str ()); |
6361 | 911 if (tmp_msg[len-1] == '\n') |
912 { | |
913 if (len > 1) | |
914 { | |
915 tmp_msg[len - 1] = '\0'; | |
6483 | 916 rethrow_error (id.c_str (), "%s\n", tmp_msg); |
6361 | 917 } |
918 } | |
919 else | |
6483 | 920 rethrow_error (id.c_str (), "%s", tmp_msg); |
6361 | 921 delete [] tmp_msg; |
922 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
923 // FIXME -- is this the right thing to do for |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
924 // Vlast_error_stack? Should it be saved and restored |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
925 // with unwind_protect? |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
926 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
927 Vlast_error_stack = err_stack; |
6361 | 928 |
6483 | 929 if (err.contains ("stack")) |
6361 | 930 { |
931 if (file.empty ()) | |
932 { | |
933 if (nm.empty ()) | |
934 { | |
935 if (l > 0) | |
6483 | 936 { |
937 if (c > 0) | |
938 pr_where_1 ("error: near line %d, column %d", | |
939 l, c); | |
940 else | |
941 pr_where_1 ("error: near line %d", l); | |
942 } | |
6361 | 943 } |
944 else | |
945 { | |
946 if (l > 0) | |
6483 | 947 { |
948 if (c > 0) | |
949 pr_where_1 ("error: called from `%s' near line %d, column %d", | |
950 nm.c_str (), l, c); | |
951 else | |
952 pr_where_1 ("error: called from `%d' near line %d", nm.c_str (), l); | |
953 } | |
6361 | 954 } |
955 } | |
956 else | |
957 { | |
958 if (nm.empty ()) | |
959 { | |
960 if (l > 0) | |
6483 | 961 { |
962 if (c > 0) | |
963 pr_where_1 ("error: in file %s near line %d, column %d", | |
964 file.c_str (), l, c); | |
965 else | |
966 pr_where_1 ("error: in file %s near line %d", file.c_str (), l); | |
967 } | |
6361 | 968 } |
969 else | |
970 { | |
971 if (l > 0) | |
6483 | 972 { |
973 if (c > 0) | |
974 pr_where_1 ("error: called from `%s' in file %s near line %d, column %d", | |
975 nm.c_str (), file.c_str (), l, c); | |
976 else | |
977 pr_where_1 ("error: called from `%d' in file %s near line %d", nm.c_str (), file.c_str (), l); | |
978 } | |
6361 | 979 } |
980 } | |
981 } | |
982 } | |
983 else | |
984 error ("rethrow: structure must contain the fields 'message and 'identifier'"); | |
985 } | |
986 } | |
987 return retval; | |
988 } | |
989 | |
1957 | 990 DEFUN (error, args, , |
3373 | 991 "-*- texinfo -*-\n\ |
992 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\ | |
7252 | 993 @deftypefnx {Built-in Function} {} error (@var{id}, @var{template}, @dots{})\n\ |
5781 | 994 Format the optional arguments under the control of the template string\n\ |
995 @var{template} using the same rules as the @code{printf} family of\n\ | |
996 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
997 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
998 string @samp{error: }.\n\ | |
3373 | 999 \n\ |
1000 Calling @code{error} also sets Octave's internal error state such that\n\ | |
1001 control will return to the top level without evaluating any more\n\ | |
1002 commands. This is useful for aborting from functions or scripts.\n\ | |
897 | 1003 \n\ |
3373 | 1004 If the error message does not end with a new line character, Octave will\n\ |
1005 print a traceback of all the function calls leading to the error. For\n\ | |
1006 example, given the following function definitions:\n\ | |
1007 \n\ | |
1008 @example\n\ | |
1009 @group\n\ | |
6671 | 1010 function f () g (); end\n\ |
1011 function g () h (); end\n\ | |
3373 | 1012 function h () nargin == 1 || error (\"nargin != 1\"); end\n\ |
1013 @end group\n\ | |
1014 @end example\n\ | |
1489 | 1015 \n\ |
3373 | 1016 @noindent\n\ |
1017 calling the function @code{f} will result in a list of messages that\n\ | |
1018 can help you to quickly locate the exact location of the error:\n\ | |
1489 | 1019 \n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1020 @example\n\ |
3373 | 1021 @group\n\ |
1022 f ()\n\ | |
1023 error: nargin != 1\n\ | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1024 error: called from:\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1025 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
|
1026 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
|
1027 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
|
1028 error: f at line 1, column 15\n\ |
3373 | 1029 @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
|
1030 @end example\n\ |
3373 | 1031 \n\ |
1032 If the error message ends in a new line character, Octave will print the\n\ | |
1033 message but will not display any traceback messages as it returns\n\ | |
1034 control to the top level. For example, modifying the error message\n\ | |
1035 in the previous example to end in a new line causes Octave to only print\n\ | |
1036 a single message:\n\ | |
1037 \n\ | |
1038 @example\n\ | |
1039 @group\n\ | |
1040 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\ | |
1041 f ()\n\ | |
1042 error: nargin != 1\n\ | |
1043 @end group\n\ | |
1044 @end example\n\ | |
1045 @end deftypefn") | |
897 | 1046 { |
7252 | 1047 octave_value retval; |
1048 | |
1049 int nargin = args.length (); | |
1050 | |
1051 octave_value_list nargs = args; | |
1052 | |
1053 std::string id; | |
1054 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1055 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
|
1056 print_usage (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1057 else |
7252 | 1058 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1059 if (nargin > 1) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1060 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1061 std::string arg1 = args(0).string_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1062 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1063 if (! error_state) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1064 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1065 if (arg1.find ('%') == std::string::npos) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1066 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1067 id = arg1; |
5567 | 1068 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1069 nargs.resize (nargin-1); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1070 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1071 for (int i = 1; i < nargin; i++) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1072 nargs(i-1) = args(i); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1073 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1074 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1075 else |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1076 return retval; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1077 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1078 else if (nargin == 1 && args(0).is_map ()) |
7252 | 1079 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1080 octave_value_list tmp; |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1081 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1082 Octave_map m = args(0).map_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1083 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1084 if (m.numel () == 1) |
7252 | 1085 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1086 if (m.contains ("message")) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1087 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1088 Cell c = m.contents ("message"); |
7252 | 1089 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1090 if (! c.is_empty () && c(0).is_string ()) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1091 nargs(0) = c(0).string_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1092 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1093 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1094 if (m.contains ("identifier")) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1095 { |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1096 Cell c = m.contents ("identifier"); |
7252 | 1097 |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1098 if (! c.is_empty () && c(0).is_string ()) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1099 id = c(0).string_value (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1100 } |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1101 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1102 // FIXME -- also need to handle "stack" field in error |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1103 // structure, but that will require some more significant |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1104 // surgery on handle_message, error_with_id, etc. |
7252 | 1105 } |
1106 } | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1107 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1108 handle_message (error_with_id, id.c_str (), "unspecified error", nargs); |
7252 | 1109 } |
1110 | |
3934 | 1111 return retval; |
1489 | 1112 } |
897 | 1113 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
1114 DEFUN (warning, args, nargout, |
3373 | 1115 "-*- texinfo -*-\n\ |
5781 | 1116 @deftypefn {Built-in Function} {} warning (@var{template}, @dots{})\n\ |
7252 | 1117 @deftypefnx {Built-in Function} {} warning (@var{id}, @var{template}, @dots{})\n\ |
5781 | 1118 Format the optional arguments under the control of the template string\n\ |
1119 @var{template} using the same rules as the @code{printf} family of\n\ | |
1120 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
1121 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
1122 string @samp{warning: }.\n\ | |
1123 You should use this function when you want to notify the user\n\ | |
3600 | 1124 of an unusual condition, but only when it makes sense for your program\n\ |
1125 to go on.\n\ | |
5781 | 1126 \n\ |
1127 The optional message identifier allows users to enable or disable\n\ | |
1128 warnings tagged by @var{id}. The special identifier @samp{\"all\"} may\n\ | |
1129 be used to set the state of all warnings.\n\ | |
1130 \n\ | |
1131 @deftypefnx {Built-in Function} {} warning (\"on\", @var{id})\n\ | |
1132 @deftypefnx {Built-in Function} {} warning (\"off\", @var{id})\n\ | |
1133 @deftypefnx {Built-in Function} {} warning (\"error\", @var{id})\n\ | |
1134 @deftypefnx {Built-in Function} {} warning (\"query\", @var{id})\n\ | |
6653 | 1135 Set or query the state of a particular warning using the identifier\n\ |
5781 | 1136 @var{id}. If the identifier is omitted, a value of @samp{\"all\"} is\n\ |
1137 assumed. If you set the state of a warning to @samp{\"error\"}, the\n\ | |
1138 warning named by @var{id} is handled as if it were an error instead.\n\ | |
5783 | 1139 @seealso{warning_ids}\n\ |
3373 | 1140 @end deftypefn") |
1489 | 1141 { |
5567 | 1142 octave_value retval; |
3934 | 1143 |
5567 | 1144 int nargin = args.length (); |
1145 int argc = nargin + 1; | |
3934 | 1146 |
3935 | 1147 bool done = false; |
3934 | 1148 |
5567 | 1149 if (argc > 1 && args.all_strings_p ()) |
3935 | 1150 { |
1151 string_vector argv = args.make_argv ("warning"); | |
1152 | |
1153 if (! error_state) | |
3934 | 1154 { |
5567 | 1155 std::string arg1 = argv(1); |
1156 std::string arg2 = "all"; | |
1157 | |
1158 if (argc == 3) | |
1159 arg2 = argv(2); | |
1160 | |
1161 if (arg1 == "on" || arg1 == "off" || arg1 == "error") | |
3934 | 1162 { |
5567 | 1163 Octave_map old_warning_options = warning_options; |
1164 | |
1165 if (arg2 == "all") | |
1166 { | |
1167 Octave_map tmp; | |
3934 | 1168 |
7202 | 1169 Cell id (1, 1); |
1170 Cell st (1, 1); | |
1171 | |
1172 id(0) = arg2; | |
1173 st(0) = arg1; | |
1174 | |
1175 // Since internal Octave functions are not | |
1176 // compatible, turning all warnings into errors | |
1177 // should leave the state of | |
1178 // Octave:matlab-incompatible alone. | |
1179 | |
1180 if (arg1 == "error" | |
1181 && warning_options.contains ("identifier")) | |
1182 { | |
7206 | 1183 octave_idx_type n = 1; |
1184 | |
7202 | 1185 Cell tid = warning_options.contents ("identifier"); |
1186 Cell tst = warning_options.contents ("state"); | |
1187 | |
1188 for (octave_idx_type i = 0; i < tid.numel (); i++) | |
1189 { | |
1190 octave_value vid = tid(i); | |
1191 | |
7206 | 1192 if (vid.is_string ()) |
7202 | 1193 { |
7206 | 1194 std::string key = vid.string_value (); |
7202 | 1195 |
7206 | 1196 if (key == "Octave:matlab-incompatible" |
1197 || key == "Octave:single-quote-string") | |
1198 { | |
1199 id.resize (dim_vector (1, n+1)); | |
1200 st.resize (dim_vector (1, n+1)); | |
7202 | 1201 |
7206 | 1202 id(n) = tid(i); |
1203 st(n) = tst(i); | |
1204 | |
1205 n++; | |
1206 } | |
7202 | 1207 } |
1208 } | |
1209 } | |
1210 | |
1211 tmp.assign ("identifier", id); | |
1212 tmp.assign ("state", st); | |
5567 | 1213 |
1214 warning_options = tmp; | |
1215 | |
3935 | 1216 done = true; |
1217 } | |
5567 | 1218 else if (arg2 == "backtrace") |
1219 { | |
1220 if (arg1 != "error") | |
1221 { | |
1222 Vbacktrace_on_warning = (arg1 == "on"); | |
1223 done = true; | |
1224 } | |
1225 } | |
1226 else if (arg2 == "debug") | |
1227 { | |
1228 if (arg1 != "error") | |
1229 { | |
5794 | 1230 Vdebug_on_warning = (arg1 == "on"); |
5567 | 1231 done = true; |
1232 } | |
1233 } | |
1234 else if (arg2 == "verbose") | |
1235 { | |
1236 if (arg1 != "error") | |
1237 { | |
1238 Vverbose_warning = (arg1 == "on"); | |
1239 done = true; | |
1240 } | |
1241 } | |
5582 | 1242 else if (arg2 == "quiet") |
1243 { | |
1244 if (arg1 != "error") | |
1245 { | |
1246 Vquiet_warning = (arg1 == "on"); | |
1247 done = true; | |
1248 } | |
1249 } | |
5567 | 1250 else |
3935 | 1251 { |
5567 | 1252 if (arg2 == "last") |
1253 arg2 = Vlast_warning_id; | |
1254 | |
1255 if (arg2 == "all") | |
5794 | 1256 initialize_warning_options (arg1); |
5567 | 1257 else |
1258 { | |
1259 Cell ident = warning_options.contents ("identifier"); | |
1260 Cell state = warning_options.contents ("state"); | |
1261 | |
1262 octave_idx_type nel = ident.numel (); | |
1263 | |
1264 bool found = false; | |
1265 | |
1266 for (octave_idx_type i = 0; i < nel; i++) | |
1267 { | |
1268 if (ident(i).string_value () == arg2) | |
1269 { | |
5775 | 1270 // FIXME -- if state for "all" is |
5567 | 1271 // same as arg1, we can simply remove the |
1272 // item from the list. | |
1273 | |
1274 state(i) = arg1; | |
1275 warning_options.assign ("state", state); | |
1276 found = true; | |
1277 break; | |
1278 } | |
1279 } | |
1280 | |
1281 if (! found) | |
1282 { | |
5775 | 1283 // FIXME -- if state for "all" is |
5567 | 1284 // same as arg1, we don't need to do anything. |
1285 | |
1286 ident.resize (dim_vector (1, nel+1)); | |
1287 state.resize (dim_vector (1, nel+1)); | |
1288 | |
1289 ident(nel) = arg2; | |
1290 state(nel) = arg1; | |
1291 | |
1292 warning_options.clear (); | |
1293 | |
1294 warning_options.assign ("identifier", ident); | |
1295 warning_options.assign ("state", state); | |
1296 } | |
1297 } | |
1298 | |
3935 | 1299 done = true; |
1300 } | |
5567 | 1301 |
1302 if (done && nargout > 0) | |
6427 | 1303 retval = old_warning_options; |
5567 | 1304 } |
1305 else if (arg1 == "query") | |
1306 { | |
1307 if (arg2 == "all") | |
1308 retval = warning_options; | |
1309 else if (arg2 == "backtrace" || arg2 == "debug" | |
5582 | 1310 || arg2 == "verbose" || arg2 == "quiet") |
5567 | 1311 { |
1312 Octave_map tmp; | |
1313 tmp.assign ("identifier", arg2); | |
1314 if (arg2 == "backtrace") | |
1315 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); | |
1316 else if (arg2 == "debug") | |
1317 tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); | |
5582 | 1318 else if (arg2 == "verbose") |
1319 tmp.assign ("state", Vverbose_warning ? "on" : "off"); | |
5567 | 1320 else |
5582 | 1321 tmp.assign ("state", Vquiet_warning ? "on" : "off"); |
1322 | |
1323 retval = tmp; | |
5567 | 1324 } |
1325 else | |
3935 | 1326 { |
5567 | 1327 if (arg2 == "last") |
1328 arg2 = Vlast_warning_id; | |
1329 | |
1330 Cell ident = warning_options.contents ("identifier"); | |
1331 Cell state = warning_options.contents ("state"); | |
1332 | |
1333 octave_idx_type nel = ident.numel (); | |
1334 | |
1335 bool found = false; | |
1336 | |
1337 std::string val; | |
1338 | |
1339 for (octave_idx_type i = 0; i < nel; i++) | |
1340 { | |
1341 if (ident(i).string_value () == arg2) | |
1342 { | |
1343 val = state(i).string_value (); | |
1344 found = true; | |
1345 break; | |
1346 } | |
1347 } | |
1348 | |
5781 | 1349 if (! found) |
1350 { | |
1351 for (octave_idx_type i = 0; i < nel; i++) | |
1352 { | |
1353 if (ident(i).string_value () == "all") | |
1354 { | |
1355 val = state(i).string_value (); | |
1356 found = true; | |
1357 break; | |
1358 } | |
1359 } | |
1360 } | |
1361 | |
5567 | 1362 if (found) |
1363 { | |
1364 Octave_map tmp; | |
1365 | |
1366 tmp.assign ("identifier", arg2); | |
1367 tmp.assign ("state", val); | |
1368 | |
1369 retval = tmp; | |
1370 } | |
1371 else | |
5781 | 1372 error ("warning: unable to find default warning state!"); |
3935 | 1373 } |
5567 | 1374 |
1375 done = true; | |
3935 | 1376 } |
3934 | 1377 } |
1378 } | |
5567 | 1379 else if (argc == 1) |
1380 { | |
1381 retval = warning_options; | |
3934 | 1382 |
5567 | 1383 done = true; |
1384 } | |
1385 else if (argc == 2) | |
1386 { | |
1387 octave_value arg = args(0); | |
1388 | |
1389 Octave_map old_warning_options = warning_options; | |
1390 | |
1391 if (arg.is_map ()) | |
1392 { | |
1393 Octave_map m = arg.map_value (); | |
1394 | |
1395 if (m.contains ("identifier") && m.contains ("state")) | |
6427 | 1396 warning_options = m; |
5567 | 1397 else |
1398 error ("warning: expecting structure with fields `identifier' and `state'"); | |
1399 | |
1400 done = true; | |
1401 | |
1402 if (nargout > 0) | |
1403 retval = old_warning_options; | |
1404 } | |
1405 } | |
1406 | |
1407 if (! (error_state || done)) | |
3935 | 1408 { |
5567 | 1409 octave_value_list nargs = args; |
1410 | |
1411 std::string id; | |
1412 | |
1413 if (nargin > 1) | |
1414 { | |
1415 std::string arg1 = args(0).string_value (); | |
1416 | |
1417 if (! error_state) | |
1418 { | |
8021 | 1419 if (arg1.find ('%') == std::string::npos) |
5567 | 1420 { |
1421 id = arg1; | |
1422 | |
1423 nargs.resize (nargin-1); | |
1424 | |
1425 for (int i = 1; i < nargin; i++) | |
1426 nargs(i-1) = args(i); | |
1427 } | |
1428 } | |
1429 else | |
1430 return retval; | |
1431 } | |
1432 | |
3935 | 1433 std::string prev_msg = Vlast_warning_message; |
1434 | |
5567 | 1435 std::string curr_msg = handle_message (warning_with_id, id.c_str (), |
1436 "unspecified warning", nargs); | |
3935 | 1437 |
1438 if (nargout > 0) | |
5567 | 1439 retval = prev_msg; |
3935 | 1440 } |
1441 | |
3934 | 1442 return retval; |
1443 } | |
1444 | |
5904 | 1445 void |
5794 | 1446 disable_warning (const std::string& id) |
1447 { | |
1448 octave_value_list args; | |
1449 | |
1450 args(1) = id; | |
1451 args(0) = "off"; | |
1452 | |
1453 Fwarning (args, 0); | |
1454 } | |
1455 | |
1456 void | |
1457 initialize_default_warning_state (void) | |
1458 { | |
1459 initialize_warning_options ("on"); | |
1460 | |
1461 // Most people will want to have the following disabled. | |
1462 | |
1463 disable_warning ("Octave:array-to-scalar"); | |
1464 disable_warning ("Octave:array-to-vector"); | |
1465 disable_warning ("Octave:empty-list-elements"); | |
1466 disable_warning ("Octave:fortran-indexing"); | |
1467 disable_warning ("Octave:imag-to-real"); | |
1468 disable_warning ("Octave:matlab-incompatible"); | |
1469 disable_warning ("Octave:missing-semicolon"); | |
1470 disable_warning ("Octave:neg-dim-as-zero"); | |
1471 disable_warning ("Octave:resize-on-range-error"); | |
1472 disable_warning ("Octave:separator-insert"); | |
1473 disable_warning ("Octave:single-quote-string"); | |
1474 disable_warning ("Octave:str-to-num"); | |
1475 disable_warning ("Octave:string-concat"); | |
1476 disable_warning ("Octave:variable-switch-label"); | |
8039
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1477 disable_warning ("Octave:int-convert-nan"); |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1478 disable_warning ("Octave:int-convert-non-int-val"); |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1479 disable_warning ("Octave:int-convert-overflow"); |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1480 disable_warning ("Octave:int-math-overflow"); |
9588
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
1481 disable_warning ("Octave:complex-cmp-ops"); |
5794 | 1482 } |
1483 | |
6361 | 1484 DEFUN (lasterror, args, , |
1485 "-*- texinfo -*-\n\ | |
1486 @deftypefn {Built-in Function} {@var{err} =} lasterror (@var{err})\n\ | |
1487 @deftypefnx {Built-in Function} {} lasterror ('reset')\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1488 Returns or sets the last error message. Called without any arguments\n\ |
6361 | 1489 returns a structure containing the last error message, as well as other\n\ |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1490 information related to this error. The elements of this structure are:\n\ |
6361 | 1491 \n\ |
1492 @table @asis\n\ | |
1493 @item 'message'\n\ | |
1494 The text of the last error message\n\ | |
1495 @item 'identifier'\n\ | |
1496 The message identifier of this error message\n\ | |
1497 @item 'stack'\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1498 A structure containing information on where the message occurred. This might\n\ |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8333
diff
changeset
|
1499 be an empty structure if this in the case where this information cannot\n\ |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1500 be obtained. The fields of this structure are:\n\ |
6361 | 1501 \n\ |
1502 @table @asis\n\ | |
1503 @item 'file'\n\ | |
1504 The name of the file where the error occurred\n\ | |
1505 @item 'name'\n\ | |
7001 | 1506 The name of function in which the error occurred\n\ |
6361 | 1507 @item 'line'\n\ |
7001 | 1508 The line number at which the error occurred\n\ |
6361 | 1509 @item 'column'\n\ |
1510 An optional field with the column number at which the error occurred\n\ | |
1511 @end table\n\ | |
1512 @end table\n\ | |
1513 \n\ | |
1514 The @var{err} structure may also be passed to @code{lasterror} to set the\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1515 information about the last error. The only constraint on @var{err} in that\n\ |
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8973
diff
changeset
|
1516 case is that it is a scalar structure. Any fields of @var{err} that match\n\ |
6361 | 1517 the above are set to the value passed in @var{err}, while other fields are\n\ |
1518 set to their default values.\n\ | |
1519 \n\ | |
1520 If @code{lasterror} is called with the argument 'reset', all values take\n\ | |
1521 their default values.\n\ | |
1522 @end deftypefn") | |
1523 { | |
1524 octave_value retval; | |
1525 int nargin = args.length(); | |
1526 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
1527 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1528 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
1529 unwind_protect::protect_var (error_state); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1530 error_state = 0; |
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1531 |
6361 | 1532 if (nargin < 2) |
1533 { | |
1534 Octave_map err; | |
1535 | |
1536 err.assign ("message", Vlast_error_message); | |
1537 err.assign ("identifier", Vlast_error_id); | |
1538 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1539 err.assign ("stack", octave_value (Vlast_error_stack)); |
6361 | 1540 |
1541 if (nargin == 1) | |
1542 { | |
1543 if (args(0).is_string()) | |
1544 { | |
6483 | 1545 if (args(0).string_value () == "reset") |
6361 | 1546 { |
1547 Vlast_error_message = std::string(); | |
1548 Vlast_error_id = std::string(); | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1549 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1550 Vlast_error_stack = initialize_last_error_stack (); |
6361 | 1551 } |
1552 else | |
1553 error("lasterror: unrecognized string argument"); | |
1554 } | |
1555 else if (args(0).is_map ()) | |
1556 { | |
6483 | 1557 Octave_map new_err = args(0).map_value (); |
6361 | 1558 std::string new_error_message; |
1559 std::string new_error_id; | |
1560 std::string new_error_file; | |
1561 std::string new_error_name; | |
1562 int new_error_line = -1; | |
1563 int new_error_column = -1; | |
1564 | |
6483 | 1565 if (! error_state && new_err.contains ("message")) |
6361 | 1566 { |
1567 const std::string tmp = | |
6483 | 1568 new_err.contents("message")(0).string_value (); |
6361 | 1569 new_error_message = tmp; |
1570 } | |
1571 | |
6483 | 1572 if (! error_state && new_err.contains ("identifier")) |
6361 | 1573 { |
1574 const std::string tmp = | |
6483 | 1575 new_err.contents("identifier")(0).string_value (); |
6361 | 1576 new_error_id = tmp; |
1577 } | |
1578 | |
6483 | 1579 if (! error_state && new_err.contains ("stack")) |
6361 | 1580 { |
1581 Octave_map new_err_stack = | |
6483 | 1582 new_err.contents("identifier")(0).map_value (); |
6361 | 1583 |
6483 | 1584 if (! error_state && new_err_stack.contains ("file")) |
6361 | 1585 { |
1586 const std::string tmp = | |
6483 | 1587 new_err_stack.contents("file")(0).string_value (); |
6361 | 1588 new_error_file = tmp; |
1589 } | |
1590 | |
6483 | 1591 if (! error_state && new_err_stack.contains ("name")) |
6361 | 1592 { |
1593 const std::string tmp = | |
6483 | 1594 new_err_stack.contents("name")(0).string_value (); |
6361 | 1595 new_error_name = tmp; |
1596 } | |
1597 | |
6483 | 1598 if (! error_state && new_err_stack.contains ("line")) |
6361 | 1599 { |
1600 const int tmp = | |
6483 | 1601 new_err_stack.contents("line")(0).nint_value (); |
6361 | 1602 new_error_line = tmp; |
1603 } | |
1604 | |
6483 | 1605 if (! error_state && new_err_stack.contains ("column")) |
6361 | 1606 { |
1607 const int tmp = | |
6483 | 1608 new_err_stack.contents("column")(0).nint_value (); |
6361 | 1609 new_error_column = tmp; |
1610 } | |
1611 } | |
1612 | |
1613 if (! error_state) | |
1614 { | |
1615 Vlast_error_message = new_error_message; | |
1616 Vlast_error_id = new_error_id; | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1617 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1618 octave_idx_type curr_frame = -1; |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1619 |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1620 Vlast_error_stack |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1621 = octave_call_stack::backtrace (0, curr_frame); |
6361 | 1622 } |
1623 } | |
1624 else | |
1625 error ("lasterror: argument must be a structure or a string"); | |
1626 } | |
1627 | |
6483 | 1628 if (! error_state) |
6361 | 1629 retval = err; |
1630 } | |
1631 else | |
1632 print_usage (); | |
1633 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
1634 unwind_protect::run_frame (uwp_frame); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1635 |
6361 | 1636 return retval; |
1637 } | |
1638 | |
5567 | 1639 DEFUN (lasterr, args, nargout, |
3935 | 1640 "-*- texinfo -*-\n\ |
5567 | 1641 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lasterr (@var{msg}, @var{msgid})\n\ |
3935 | 1642 Without any arguments, return the last error message. With one\n\ |
5567 | 1643 argument, set the last error message to @var{msg}. With two arguments,\n\ |
1644 also set the last message identifier.\n\ | |
3935 | 1645 @end deftypefn") |
1646 { | |
1647 octave_value_list retval; | |
1648 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
1649 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1650 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
1651 unwind_protect::protect_var (error_state); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1652 error_state = 0; |
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1653 |
3935 | 1654 int argc = args.length () + 1; |
1655 | |
5567 | 1656 if (argc < 4) |
5335 | 1657 { |
1658 string_vector argv = args.make_argv ("lasterr"); | |
3935 | 1659 |
5335 | 1660 if (! error_state) |
1661 { | |
5567 | 1662 std::string prev_error_id = Vlast_error_id; |
1663 std::string prev_error_message = Vlast_error_message; | |
1664 | |
1665 if (argc > 2) | |
1666 Vlast_error_id = argv(2); | |
1667 | |
1668 if (argc > 1) | |
5335 | 1669 Vlast_error_message = argv(1); |
5567 | 1670 |
1671 if (argc == 1 || nargout > 0) | |
1672 { | |
1673 retval(1) = prev_error_id; | |
1674 retval(0) = prev_error_message; | |
1675 } | |
5335 | 1676 } |
5567 | 1677 else |
5582 | 1678 error ("lasterr: expecting arguments to be character strings"); |
5335 | 1679 } |
3935 | 1680 else |
5823 | 1681 print_usage (); |
3935 | 1682 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9205
diff
changeset
|
1683 unwind_protect::run_frame (uwp_frame); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1684 |
3935 | 1685 return retval; |
1686 } | |
1687 | |
4699 | 1688 // For backward compatibility. |
1689 DEFALIAS (error_text, lasterr); | |
1690 DEFALIAS (__error_text__, lasterr); | |
1691 | |
5567 | 1692 DEFUN (lastwarn, args, nargout, |
3934 | 1693 "-*- texinfo -*-\n\ |
5567 | 1694 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lastwarn (@var{msg}, @var{msgid})\n\ |
3935 | 1695 Without any arguments, return the last warning message. With one\n\ |
5567 | 1696 argument, set the last warning message to @var{msg}. With two arguments,\n\ |
1697 also set the last message identifier.\n\ | |
3934 | 1698 @end deftypefn") |
1699 { | |
1700 octave_value_list retval; | |
1701 | |
1702 int argc = args.length () + 1; | |
1703 | |
5567 | 1704 if (argc < 4) |
1705 { | |
1706 string_vector argv = args.make_argv ("lastwarn"); | |
1707 | |
1708 if (! error_state) | |
1709 { | |
1710 std::string prev_warning_id = Vlast_warning_id; | |
1711 std::string prev_warning_message = Vlast_warning_message; | |
1712 | |
1713 if (argc > 2) | |
1714 Vlast_warning_id = argv(2); | |
3934 | 1715 |
5567 | 1716 if (argc > 1) |
1717 Vlast_warning_message = argv(1); | |
1718 | |
1719 if (argc == 1 || nargout > 0) | |
1720 { | |
5582 | 1721 warning_state = 0; |
5567 | 1722 retval(1) = prev_warning_id; |
1723 retval(0) = prev_warning_message; | |
1724 } | |
1725 } | |
1726 else | |
1727 error ("lastwarn: expecting arguments to be character strings"); | |
1728 } | |
3934 | 1729 else |
5823 | 1730 print_usage (); |
3934 | 1731 |
1732 return retval; | |
897 | 1733 } |
1734 | |
1957 | 1735 DEFUN (usage, args, , |
3373 | 1736 "-*- texinfo -*-\n\ |
1737 @deftypefn {Built-in Function} {} usage (@var{msg})\n\ | |
1738 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\ | |
1739 set Octave's internal error state such that control will return to the\n\ | |
1740 top level without evaluating any more commands. This is useful for\n\ | |
1741 aborting from functions.\n\ | |
1742 \n\ | |
1743 After @code{usage} is evaluated, Octave will print a traceback of all\n\ | |
1744 the function calls leading to the usage message.\n\ | |
899 | 1745 \n\ |
3373 | 1746 You should use this function for reporting problems errors that result\n\ |
1747 from an improper call to a function, such as calling a function with an\n\ | |
1748 incorrect number of arguments, or with arguments of the wrong type. For\n\ | |
1749 example, most functions distributed with Octave begin with code like\n\ | |
1750 this\n\ | |
1751 \n\ | |
1752 @example\n\ | |
1753 @group\n\ | |
1754 if (nargin != 2)\n\ | |
1755 usage (\"foo (a, b)\");\n\ | |
1756 endif\n\ | |
1757 @end group\n\ | |
1758 @end example\n\ | |
1759 \n\ | |
1760 @noindent\n\ | |
1761 to check for the proper number of arguments.\n\ | |
1762 @end deftypefn") | |
899 | 1763 { |
3934 | 1764 octave_value_list retval; |
5567 | 1765 handle_message (usage_with_id, "", "unknown", args); |
3934 | 1766 return retval; |
899 | 1767 } |
1768 | |
5794 | 1769 DEFUN (beep_on_error, args, nargout, |
1770 "-*- texinfo -*-\n\ | |
1771 @deftypefn {Built-in Function} {@var{val} =} beep_on_error ()\n\ | |
1772 @deftypefnx {Built-in Function} {@var{old_val} =} beep_on_error (@var{new_val})\n\ | |
1773 Query or set the internal variable that controls whether Octave will try\n\ | |
1774 to ring the terminal bell before printing an error message.\n\ | |
1775 @end deftypefn") | |
3707 | 1776 { |
5794 | 1777 return SET_INTERNAL_VARIABLE (beep_on_error); |
3707 | 1778 } |
1779 | |
5794 | 1780 DEFUN (debug_on_error, args, nargout, |
3373 | 1781 "-*- texinfo -*-\n\ |
5794 | 1782 @deftypefn {Built-in Function} {@var{val} =} debug_on_error ()\n\ |
1783 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_error (@var{new_val})\n\ | |
1784 Query or set the internal variable that controls whether Octave will try\n\ | |
3707 | 1785 to enter the debugger when an error is encountered. This will also\n\ |
1786 inhibit printing of the normal traceback message (you will only see\n\ | |
5794 | 1787 the top-level error message).\n\ |
1788 @end deftypefn") | |
1789 { | |
1790 return SET_INTERNAL_VARIABLE (debug_on_error); | |
1791 } | |
3707 | 1792 |
5794 | 1793 DEFUN (debug_on_warning, args, nargout, |
3707 | 1794 "-*- texinfo -*-\n\ |
5794 | 1795 @deftypefn {Built-in Function} {@var{val} =} debug_on_warning ()\n\ |
1796 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_warning (@var{new_val})\n\ | |
1797 Query or set the internal variable that controls whether Octave will try\n\ | |
1798 to enter the debugger when a warning is encountered.\n\ | |
1799 @end deftypefn") | |
1800 { | |
1801 return SET_INTERNAL_VARIABLE (debug_on_warning); | |
2174 | 1802 } |
1803 | |
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
|
1804 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
|
1805 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
|
1806 { |
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
|
1807 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
|
1808 } |
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
|
1809 |
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
|
1810 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
|
1811 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
|
1812 { |
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
|
1813 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
|
1814 } |
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
|
1815 |
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
|
1816 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
|
1817 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
|
1818 { |
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
|
1819 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
|
1820 } |
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
|
1821 |
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
|
1822 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
|
1823 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
|
1824 { |
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
|
1825 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
|
1826 } |
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
|
1827 |
1 | 1828 /* |
1829 ;;; Local Variables: *** | |
1830 ;;; mode: C++ *** | |
1831 ;;; End: *** | |
1832 */ |