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