Mercurial > octave
annotate libinterp/corefcn/error.cc @ 27161:7883e6e71b0a
additional refactoring of error handling functions
* error.h, error.cc. Move most functions inside error_system class.
Global non-member functions now get interpreter error_system object
and call class member fuctions through that object.
* graphics.cc (base_graphics_object::remove_all_listeners):
Use interpreter_try instead of directly saving and restoring error
systsem state here.
* interpreter.cc (interpreter::interpreter): Don't call
initialize_default_warning_state. That is now handled by constructing
the error_system object.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 04 Jun 2019 13:15:25 +0000 |
parents | 6b0c61a5a0f0 |
children | f27002104c5b |
rev | line source |
---|---|
1 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26350
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24441
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24441
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
10 (at your option) any later version. |
1 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
15 GNU General Public License for more details. |
1 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24441
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
1 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21698
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
1 | 25 #endif |
26 | |
1343 | 27 #include <cstdarg> |
23448
e1c02e7126a9
avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
28 #include <cstdlib> |
1633 | 29 #include <cstring> |
1343 | 30 |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
31 #include <iomanip> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
32 #include <iostream> |
5765 | 33 #include <sstream> |
1728 | 34 #include <string> |
35 | |
23137
334119c390b3
move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents:
23127
diff
changeset
|
36 #include "bp-table.h" |
23454
30b6eccd6708
use builtin-defun-decls.h to ensure declarations of interpreter functions
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
37 #include "builtin-defun-decls.h" |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
22089
diff
changeset
|
38 #include "call-stack.h" |
1352 | 39 #include "defun.h" |
1 | 40 #include "error.h" |
3707 | 41 #include "input.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
42 #include "interpreter-private.h" |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
43 #include "interpreter.h" |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
44 #include "oct-map.h" |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21990
diff
changeset
|
45 #include "octave.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
46 #include "ov-usr-fcn.h" |
2370 | 47 #include "ov.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
48 #include "ovl.h" |
1742 | 49 #include "pager.h" |
18742
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18222
diff
changeset
|
50 #include "pt-eval.h" |
3707 | 51 #include "unwind-prot.h" |
1352 | 52 #include "utils.h" |
2370 | 53 #include "variables.h" |
1 | 54 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
55 static void verror (bool save_last_error, std::ostream& os, const char *name, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
56 const char *id, const char *fmt, va_list args, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
57 bool with_cfn = false) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
58 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
59 octave::error_system& es = octave::__get_error_system__ ("verror"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
60 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
61 es.verror (save_last_error, os, name, id, fmt, args, with_cfn); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
62 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
63 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
64 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
65 vpr_where (std::ostream& os, const char *fmt, va_list args) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
66 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
67 if (fmt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
68 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
69 if (*fmt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
70 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
71 size_t len = strlen (fmt); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
72 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
73 if (len > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
74 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
75 if (fmt[len - 1] == '\n') |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
76 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
77 if (len > 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
78 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
79 std::string tmp_fmt (fmt, len - 1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
80 verror (false, os, nullptr, "", tmp_fmt.c_str (), args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
81 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
82 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
83 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
84 verror (false, os, nullptr, "", fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
85 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
86 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
87 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
88 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
89 panic ("vpr_where: invalid format"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
90 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
91 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
92 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
93 pr_where_internal (std::ostream& os, const char *fmt, ...) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
94 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
95 va_list args; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
96 va_start (args, fmt); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
97 vpr_where (os, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
98 va_end (args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
99 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
100 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
101 struct |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
102 error_stack_frame |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
103 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
104 std::string name; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
105 int line; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
106 int column; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
107 }; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
108 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
109 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
110 pr_where (std::ostream& os, const char *who, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
111 const std::list<error_stack_frame>& frames) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
112 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
113 size_t nframes = frames.size (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
114 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
115 if (nframes > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
116 pr_where_internal (os, "%s: called from\n", who); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
117 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
118 for (const auto& frm : frames) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
119 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
120 std::string fcn_name = frm.name; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
121 int line = frm.line; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
122 int column = frm.column; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
123 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
124 if (line > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
125 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
126 if (column > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
127 pr_where_internal (os, " %s at line %d column %d\n", |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
128 fcn_name.c_str (), line, column); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
129 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
130 pr_where_internal (os, " %s at line %d\n", |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
131 fcn_name.c_str (), line); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
132 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
133 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
134 pr_where_internal (os, " %s\n", fcn_name.c_str ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
135 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
136 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
137 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
138 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
139 pr_where (std::ostream& os, const char *who) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
140 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
141 octave::call_stack& cs = octave::__get_call_stack__ ("pr_where"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
142 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
143 std::list<octave::stack_frame *> call_stack_frames = cs.backtrace_frames (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
144 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
145 // Print the error message only if it is different from the previous one; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
146 // Makes the output more concise and readable. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
147 call_stack_frames.unique (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
148 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
149 std::list<error_stack_frame> frames; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
150 for (const auto *frm : call_stack_frames) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
151 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
152 error_stack_frame frame; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
153 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
154 frame.name = frm->fcn_name (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
155 frame.line = frm->line (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
156 frame.column = frm->column (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
157 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
158 frames.push_back (frame); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
159 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
160 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
161 pr_where (os, who, frames); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
162 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
163 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
164 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
165 maybe_enter_debugger (octave::execution_exception& e, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
166 bool show_stack_trace = false) |
4318 | 167 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
168 octave::error_system& es |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
169 = octave::__get_error_system__ ("maybe_enter_debugger"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
170 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
171 es.maybe_enter_debugger (e, show_stack_trace); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
172 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
173 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
174 OCTAVE_NORETURN |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
175 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
176 vusage (octave::execution_exception& e, const char *id, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
177 const char *fmt, va_list args) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
178 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
179 verror (true, std::cerr, "usage", id, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
180 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
181 maybe_enter_debugger (e); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
182 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
183 throw e; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
184 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
185 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
186 OCTAVE_NORETURN |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
187 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
188 error_1 (octave::execution_exception& e, std::ostream& os, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
189 const char *name, const char *id, const char *fmt, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
190 va_list args, bool with_cfn = false) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
191 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
192 octave::error_system& es = octave::__get_error_system__ ("error_1"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
193 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
194 es.error_1 (e, os, name, id, fmt, args, with_cfn); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
195 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
196 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
197 OCTAVE_NORETURN |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
198 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
199 error_1 (std::ostream& os, const char *name, const char *id, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
200 const char *fmt, va_list args, bool with_cfn = false) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
201 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
202 octave::error_system& es = octave::__get_error_system__ ("error_1"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
203 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
204 es.error_1 (os, name, id, fmt, args, with_cfn); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
205 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
206 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
207 static int |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
208 check_state (const std::string& state) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
209 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
210 // -1: not found |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
211 // 0: found, "off" |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
212 // 1: found, "on" |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
213 // 2: found, "error" |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
214 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
215 if (state == "off") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
216 return 0; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
217 else if (state == "on") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
218 return 1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
219 else if (state == "error") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
220 return 2; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
221 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
222 return -1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
223 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
224 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
225 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
226 vwarning (const char *id, const char *fmt, va_list args) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
227 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
228 octave::error_system& es = octave::__get_error_system__ ("warning"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
229 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
230 es.vwarning (id, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
231 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
232 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
233 static std::list<error_stack_frame> |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
234 make_stack_frame_list (const octave_map& stack) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
235 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
236 std::list<error_stack_frame> frames; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
237 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
238 Cell name = stack.contents ("name"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
239 Cell line = stack.contents ("line"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
240 Cell column; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
241 bool have_column = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
242 if (stack.contains ("column")) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
243 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
244 have_column = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
245 column = stack.contents ("column"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
246 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
247 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
248 octave_idx_type nel = name.numel (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
249 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
250 for (octave_idx_type i = 0; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
251 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
252 error_stack_frame frame; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
253 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
254 frame.name = name(i).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
255 frame.line = line(i).int_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
256 frame.column = (have_column ? column(i).int_value () : -1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
257 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
258 frames.push_back (frame); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
259 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
260 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
261 return frames; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
262 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
263 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
264 static void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
265 defun_usage_message (const char *fmt, ...) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
266 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
267 va_list args; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
268 va_start (args, fmt); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
269 error_1 (octave_stdout, nullptr, "", fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
270 va_end (args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
271 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
272 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
273 typedef void (*error_fun)(const char *, const char *, ...); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
274 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
275 static std::string |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
276 handle_message (error_fun f, const char *id, const char *msg, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
277 const octave_value_list& args, bool have_fmt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
278 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
279 std::string retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
280 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
281 std::string tmpstr; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
282 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
283 if (args.length () > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
284 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
285 octave_value arg; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
286 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
287 if (have_fmt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
288 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
289 octave_value_list tmp = Fsprintf (args, 1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
290 arg = tmp(0); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
291 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
292 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
293 arg = args(0); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
294 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
295 if (arg.is_defined ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
296 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
297 if (arg.isempty ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
298 return retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
299 else if (arg.is_string ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
300 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
301 tmpstr = arg.string_value (); // 2-stage assignment required |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
302 msg = tmpstr.c_str (); // in order to generate pointer |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
303 // to valid memory. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
304 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
305 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
306 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
307 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
308 // Ugh. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
309 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
310 size_t len = strlen (msg); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
311 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
312 if (len > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
313 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
314 if (msg[len - 1] == '\n') |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
315 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
316 if (len > 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
317 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
318 std::string tmp_msg (msg, len - 1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
319 f (id, "%s\n", tmp_msg.c_str ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
320 retval = tmp_msg; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
321 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
322 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
323 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
324 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
325 f (id, "%s", msg); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
326 retval = msg; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
327 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
328 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
329 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
330 return retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
331 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
332 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
333 // Determine whether the first argument to error or warning function |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
334 // should be handled as the message identifier or as the format string. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
335 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
336 static bool |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
337 maybe_extract_message_id (const std::string& caller, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
338 const octave_value_list& args, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
339 octave_value_list& nargs, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
340 std::string& id) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
341 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
342 nargs = args; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
343 id = ""; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
344 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
345 int nargin = args.length (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
346 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
347 bool have_fmt = nargin > 1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
348 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
349 if (nargin > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
350 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
351 std::string arg1 = args(0).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
352 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
353 // For compatibility with Matlab, an identifier must contain ':', |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
354 // but not at the beginning or the end, and it must not contain '%' |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
355 // (even if it is not a valid conversion operator) or whitespace. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
356 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
357 if (arg1.find_first_of ("% \f\n\r\t\v") == std::string::npos |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
358 && arg1.find (':') != std::string::npos |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
359 && arg1[0] != ':' |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
360 && arg1.back () != ':') |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
361 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
362 if (nargin > 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
363 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
364 id = arg1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
365 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
366 nargs.resize (nargin-1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
367 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
368 for (int i = 1; i < nargin; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
369 nargs(i-1) = args(i); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
370 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
371 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
372 nargs(0) = "call to " + caller |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
373 + " with message identifier '" + arg1 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
374 + "' requires message"; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
375 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
376 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
377 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
378 return have_fmt; |
4318 | 379 } |
380 | |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
381 namespace octave |
5567 | 382 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
383 static octave_scalar_map |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
384 init_warning_options (const std::string& state) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
385 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
386 octave_scalar_map initw; |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
387 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
388 initw.setfield ("identifier", "all"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
389 initw.setfield ("state", state); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
390 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
391 return initw; |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
392 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
393 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
394 static octave_map |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
395 init_error_stack (interpreter& interp) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
396 { |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
397 call_stack& cs = interp.get_call_stack (); |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
398 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
399 return cs.empty_backtrace (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
400 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
401 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
402 error_system::error_system (interpreter& interp) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
403 : m_interpreter (interp), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
404 m_debug_on_error (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
405 m_debug_on_caught (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
406 m_debug_on_warning (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
407 m_buffer_error_messages (0), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
408 m_in_try_catch (0), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
409 m_discard_error_messages (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
410 m_discard_warning_messages (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
411 m_beep_on_error (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
412 m_backtrace_on_warning (true), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
413 m_verbose_warning (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
414 m_quiet_warning (false), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
415 m_warning_options (init_warning_options ("on")), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
416 m_last_error_message (), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
417 m_last_warning_message (), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
418 m_last_warning_id (), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
419 m_last_error_id (), |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
420 m_last_error_stack (init_error_stack (interp)) |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
421 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
422 initialize_default_warning_state (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
423 } |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
424 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
425 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
426 error_system::debug_on_error (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
427 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
428 return set_internal_variable (m_debug_on_error, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
429 "debug_on_error"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
430 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
431 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
432 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
433 error_system::debug_on_caught (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
434 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
435 return set_internal_variable (m_debug_on_caught, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
436 "debug_on_caught"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
437 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
438 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
439 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
440 error_system::debug_on_warning (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
441 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
442 return set_internal_variable (m_debug_on_warning, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
443 "debug_on_warning"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
444 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
445 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
446 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
447 error_system::buffer_error_messages (const octave_value_list& args, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
448 int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
449 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
450 return set_internal_variable (m_buffer_error_messages, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
451 "buffer_error_messages"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
452 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
453 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
454 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
455 error_system::in_try_catch (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
456 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
457 return set_internal_variable (m_in_try_catch, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
458 "in_try_catch"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
459 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
460 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
461 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
462 error_system::discard_error_messages (const octave_value_list& args, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
463 int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
464 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
465 return set_internal_variable (m_discard_error_messages, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
466 "discard_error_messages"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
467 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
468 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
469 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
470 error_system::discard_warning_messages (const octave_value_list& args, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
471 int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
472 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
473 return set_internal_variable (m_discard_warning_messages, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
474 "discard_warning_messages"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
475 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
476 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
477 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
478 error_system::beep_on_error (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
479 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
480 return set_internal_variable (m_beep_on_error, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
481 "beep_on_error"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
482 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
483 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
484 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
485 error_system::backtrace_on_warning (const octave_value_list& args, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
486 int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
487 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
488 return set_internal_variable (m_backtrace_on_warning, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
489 "backtrace_on_warning"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
490 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
491 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
492 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
493 error_system::verbose_warning (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
494 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
495 return set_internal_variable (m_verbose_warning, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
496 "verbose_warning"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
497 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
498 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
499 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
500 error_system::quiet_warning (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
501 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
502 return set_internal_variable (m_quiet_warning, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
503 "quiet_warning"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
504 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
505 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
506 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
507 error_system::last_error_message (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
508 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
509 return set_internal_variable (m_last_error_message, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
510 "last_error_message"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
511 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
512 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
513 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
514 error_system::last_warning_message (const octave_value_list& args, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
515 int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
516 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
517 return set_internal_variable (m_last_warning_message, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
518 "last_warning_message"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
519 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
520 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
521 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
522 error_system::last_warning_id (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
523 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
524 return set_internal_variable (m_last_warning_id, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
525 "last_warning_id"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
526 } |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
527 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
528 octave_value |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
529 error_system::last_error_id (const octave_value_list& args, int nargout) |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
530 { |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
531 return set_internal_variable (m_last_error_id, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
532 "last_error_id"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
533 } |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
534 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
535 // For given warning ID, return 0 if warnings are disabled, 1 if |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
536 // enabled, and 2 if the given ID should be an error instead of a |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
537 // warning. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
538 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
539 int error_system::warning_enabled (const std::string& id) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
540 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
541 int retval = 0; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
542 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
543 int all_state = -1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
544 int id_state = -1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
545 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
546 octave_map opts = warning_options (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
547 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
548 octave_idx_type nel = opts.numel (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
549 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
550 if (nel > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
551 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
552 Cell identifier = opts.contents ("identifier"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
553 Cell state = opts.contents ("state"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
554 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
555 bool all_found = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
556 bool id_found = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
557 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
558 for (octave_idx_type i = 0; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
559 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
560 octave_value ov = identifier(i); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
561 std::string ovs = ov.string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
562 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
563 if (! all_found && ovs == "all") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
564 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
565 all_state = check_state (state(i).string_value ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
566 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
567 if (all_state >= 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
568 all_found = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
569 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
570 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
571 if (! id_found && ovs == id) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
572 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
573 id_state = check_state (state(i).string_value ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
574 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
575 if (id_state >= 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
576 id_found = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
577 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
578 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
579 if (all_found && id_found) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
580 break; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
581 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
582 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
583 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
584 // If "all" is not present, assume warnings are enabled. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
585 if (all_state == -1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
586 all_state = 1; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
587 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
588 if (all_state == 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
589 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
590 if (id_state >= 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
591 retval = id_state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
592 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
593 else if (all_state == 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
594 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
595 if (id_state == 0 || id_state == 2) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
596 retval = id_state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
597 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
598 retval = all_state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
599 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
600 else if (all_state == 2) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
601 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
602 if (id_state == 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
603 retval= id_state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
604 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
605 retval = all_state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
606 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
607 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
608 return retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
609 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
610 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
611 void error_system::verror (bool save_last_error, std::ostream& os, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
612 const char *name, const char *id, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
613 const char *fmt, va_list args, bool with_cfn) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
614 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
615 if (discard_error_messages () && ! debug_on_caught ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
616 return; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
617 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
618 if (! buffer_error_messages () || debug_on_caught ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
619 flush_stdout (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
620 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
621 // FIXME: we really want to capture the message before it has all the |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
622 // formatting goop attached to it. We probably also want just the |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
623 // message, not the traceback information. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
624 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
625 std::ostringstream output_buf; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
626 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
627 vformat (output_buf, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
628 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
629 std::string base_msg = output_buf.str (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
630 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
631 bool to_beep_or_not_to_beep_p = beep_on_error (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
632 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
633 std::string msg_string; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
634 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
635 if (to_beep_or_not_to_beep_p) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
636 msg_string = "\a"; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
637 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
638 if (name) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
639 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
640 if (in_try_catch () && ! strcmp (name, "error")) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
641 msg_string += "caught error: "; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
642 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
643 msg_string += std::string (name) + ": "; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
644 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
645 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
646 call_stack& cs = m_interpreter.get_call_stack (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
647 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
648 // If with_fcn is specified, we'll attempt to prefix the message with the name |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
649 // of the current executing function. But we'll do so only if: |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
650 // 1. the name is not empty (anonymous function) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
651 // 2. it is not already there (including the following colon) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
652 if (with_cfn) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
653 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
654 octave_function *curfcn = cs.current (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
655 if (curfcn) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
656 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
657 std::string cfn = curfcn->name (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
658 if (! cfn.empty ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
659 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
660 cfn += ':'; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
661 if (cfn.length () > base_msg.length () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
662 || base_msg.compare (0, cfn.length (), cfn) != 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
663 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
664 msg_string += cfn + ' '; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
665 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
666 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
667 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
668 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
669 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
670 msg_string += base_msg + '\n'; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
671 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
672 if (save_last_error) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
673 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
674 // This is the first error in a possible series. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
675 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
676 last_error_id (id); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
677 last_error_message (base_msg); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
678 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
679 octave_user_code *fcn = cs.current_user_code (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
680 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
681 if (fcn) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
682 last_error_stack (cs.backtrace ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
683 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
684 last_error_stack (init_error_stack (m_interpreter)); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
685 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
686 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
687 if (! buffer_error_messages () || debug_on_caught ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
688 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
689 octave_diary << msg_string; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
690 os << msg_string; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
691 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
692 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
693 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
694 void error_system::maybe_enter_debugger (execution_exception& e, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
695 bool show_stack_trace) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
696 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
697 call_stack& cs = m_interpreter.get_call_stack (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
698 tree_evaluator& tw = m_interpreter.get_evaluator (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
699 bp_table& bptab = tw.get_bp_table (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
700 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
701 if ((application::interactive () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
702 || application::forced_interactive ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
703 && ((debug_on_error () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
704 && bptab.debug_on_err (last_error_id ())) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
705 || (debug_on_caught () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
706 && bptab.debug_on_caught (last_error_id ()))) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
707 && cs.current_user_code ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
708 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
709 unwind_protect frame; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
710 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
711 frame.protect_var (m_debug_on_error); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
712 m_debug_on_error = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
713 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
714 if (show_stack_trace) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
715 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
716 std::string stack_trace = e.info (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
717 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
718 if (! stack_trace.empty ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
719 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
720 std::cerr << stack_trace; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
721 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
722 e.set_stack_trace (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
723 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
724 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
725 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
726 tw.enter_debugger (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
727 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
728 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
729 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
730 void error_system::vwarning (const char *name, const char *id, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
731 const char *fmt, va_list args) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
732 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
733 if (discard_warning_messages ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
734 return; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
735 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
736 flush_stdout (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
737 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
738 std::ostringstream output_buf; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
739 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
740 vformat (output_buf, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
741 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
742 // FIXME: we really want to capture the message before it has all the |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
743 // formatting goop attached to it. We probably also want just the |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
744 // message, not the traceback information. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
745 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
746 std::string base_msg = output_buf.str (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
747 std::string msg_string; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
748 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
749 if (name) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
750 msg_string = std::string (name) + ": "; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
751 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
752 msg_string += base_msg + '\n'; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
753 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
754 last_warning_id (id); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
755 last_warning_message (base_msg); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
756 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
757 if (! quiet_warning ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
758 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
759 octave_diary << msg_string; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
760 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
761 std::cerr << msg_string; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
762 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
763 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
764 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
765 void error_system::error_1 (execution_exception& e, std::ostream& os, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
766 const char *name, const char *id, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
767 const char *fmt, va_list args, bool with_cfn) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
768 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
769 bool show_stack_trace = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
770 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
771 if (fmt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
772 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
773 if (*fmt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
774 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
775 size_t len = strlen (fmt); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
776 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
777 if (len > 0) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
778 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
779 if (fmt[len - 1] == '\n') |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
780 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
781 if (len > 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
782 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
783 std::string tmp_fmt (fmt, len - 1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
784 verror (true, os, name, id, tmp_fmt.c_str (), |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
785 args, with_cfn); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
786 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
787 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
788 // If format ends with newline, suppress stack trace. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
789 e.set_stack_trace (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
790 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
791 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
792 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
793 verror (true, os, name, id, fmt, args, with_cfn); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
794 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
795 call_stack& cs = m_interpreter.get_call_stack (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
796 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
797 bool in_user_code = cs.current_user_code () != nullptr; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
798 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
799 if (in_user_code && ! discard_error_messages ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
800 show_stack_trace = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
801 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
802 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
803 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
804 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
805 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
806 panic ("error_1: invalid format"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
807 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
808 maybe_enter_debugger (e, show_stack_trace); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
809 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
810 throw e; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
811 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
812 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
813 void error_system::error_1 (std::ostream& os, const char *name, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
814 const char *id, const char *fmt, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
815 va_list args, bool with_cfn = false) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
816 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
817 execution_exception e = make_execution_exception ("error"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
818 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
819 error_1 (e, os, name, id, fmt, args, with_cfn); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
820 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
821 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
822 void error_system::vwarning (const char *id, const char *fmt, va_list args) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
823 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
824 int warn_opt = warning_enabled (id); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
825 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
826 if (warn_opt == 2) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
827 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
828 // Handle this warning as an error. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
829 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
830 error_1 (std::cerr, "error", id, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
831 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
832 else if (warn_opt == 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
833 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
834 bool fmt_suppresses_backtrace = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
835 size_t fmt_len = (fmt ? strlen (fmt) : 0); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
836 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n'); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
837 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
838 if (fmt_suppresses_backtrace && fmt_len > 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
839 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
840 // Strip newline before issuing warning |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
841 std::string tmp_fmt (fmt, fmt_len - 1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
842 vwarning ("warning", id, tmp_fmt.c_str (), args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
843 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
844 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
845 vwarning ("warning", id, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
846 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
847 call_stack& cs = m_interpreter.get_call_stack (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
848 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
849 bool in_user_code = cs.current_user_code () != nullptr; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
850 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
851 if (! fmt_suppresses_backtrace && in_user_code |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
852 && backtrace_on_warning () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
853 && ! discard_warning_messages ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
854 pr_where (std::cerr, "warning"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
855 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
856 tree_evaluator& tw = m_interpreter.get_evaluator (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
857 bp_table& bptab = tw.get_bp_table (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
858 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
859 if ((application::interactive () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
860 || application::forced_interactive ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
861 && debug_on_warning () && in_user_code && bptab.debug_on_warn (id)) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
862 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
863 unwind_protect frame; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
864 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
865 frame.protect_var (m_debug_on_warning); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
866 m_debug_on_warning = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
867 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
868 tw.enter_debugger (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
869 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
870 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
871 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
872 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
873 void error_system::rethrow_error (const char *id, const char *fmt, ...) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
874 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
875 va_list args; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
876 va_start (args, fmt); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
877 verror (false, std::cerr, nullptr, id, fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
878 va_end (args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
879 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
880 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
881 void error_system::rethrow_error (const std::string& id, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
882 const std::string& msg, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
883 const octave_map& stack) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
884 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
885 execution_exception e = make_execution_exception ("error"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
886 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
887 if (! stack.isempty () |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
888 && ! (stack.contains ("file") && stack.contains ("name") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
889 && stack.contains ("line"))) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
890 error ("rethrow: STACK struct must contain the fields 'file', 'name', and 'line'"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
891 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
892 last_error_id (id); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
893 last_error_message (msg); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
894 last_error_stack (stack); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
895 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
896 size_t len = msg.length (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
897 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
898 std::string tmp_msg (msg); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
899 if (len > 1 && tmp_msg[len-1] == '\n') |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
900 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
901 tmp_msg.erase (len - 1); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
902 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
903 rethrow_error (id.c_str (), "%s\n", tmp_msg.c_str ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
904 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
905 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
906 rethrow_error (id.c_str (), "%s", tmp_msg.c_str ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
907 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
908 if (! stack.isempty ()) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
909 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
910 std::ostringstream buf; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
911 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
912 pr_where (buf, "error", make_stack_frame_list (stack)); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
913 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
914 e.set_stack_trace (buf.str ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
915 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
916 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
917 throw e; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
918 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
919 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
920 void error_system::vpanic (const char *fmt, va_list args) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
921 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
922 buffer_error_messages (0); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
923 discard_error_messages (false); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
924 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
925 verror (false, std::cerr, "panic", "", fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
926 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
927 abort (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
928 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
929 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
930 void error_system::panic (const char *fmt, ...) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
931 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
932 va_list args; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
933 va_start (args, fmt); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
934 vpanic (fmt, args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
935 va_end (args); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
936 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
937 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
938 octave_scalar_map error_system::warning_query (const std::string& id_arg) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
939 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
940 octave_scalar_map retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
941 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
942 std::string id = id_arg; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
943 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
944 if (id == "last") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
945 id = last_warning_id (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
946 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
947 octave_map opts = warning_options (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
948 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
949 Cell ident = opts.contents ("identifier"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
950 Cell state = opts.contents ("state"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
951 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
952 octave_idx_type nel = ident.numel (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
953 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
954 assert (nel != 0); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
955 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
956 bool found = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
957 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
958 std::string val; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
959 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
960 for (octave_idx_type i = 0; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
961 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
962 if (ident(i).string_value () == id) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
963 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
964 val = state(i).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
965 found = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
966 break; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
967 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
968 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
969 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
970 if (! found) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
971 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
972 for (octave_idx_type i = 0; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
973 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
974 if (ident(i).string_value () == "all") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
975 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
976 val = state(i).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
977 found = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
978 break; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
979 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
980 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
981 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
982 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
983 // The warning state "all" is always supposed to remain in the list, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
984 // so we should always find a state, either explicitly or by using the |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
985 // state for "all". |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
986 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
987 assert (found); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
988 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
989 retval.assign ("identifier", id); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
990 retval.assign ("state", val); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
991 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
992 return retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
993 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
994 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
995 std::string error_system::default_warning_state (void) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
996 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
997 std::string retval = "on"; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
998 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
999 octave_map opts = warning_options (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1000 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1001 Cell ident = opts.contents ("identifier"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1002 Cell state = opts.contents ("state"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1003 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1004 octave_idx_type nel = ident.numel (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1005 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1006 for (octave_idx_type i = 0; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1007 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1008 if (ident(i).string_value () == "all") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1009 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1010 retval = state(i).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1011 break; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1012 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1013 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1014 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1015 return retval; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1016 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1017 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1018 void error_system::display_warning_options (std::ostream& os) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1019 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1020 octave_map opts = warning_options (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1021 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1022 Cell ident = opts.contents ("identifier"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1023 Cell state = opts.contents ("state"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1024 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1025 octave_idx_type nel = ident.numel (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1026 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1027 std::string all_state = default_warning_state (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1028 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1029 if (all_state == "on") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1030 os << "By default, warnings are enabled."; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1031 else if (all_state == "off") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1032 os << "By default, warnings are disabled."; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1033 else if (all_state == "error") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1034 os << "By default, warnings are treated as errors."; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1035 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1036 panic_impossible (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1037 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1038 if (nel > 1) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1039 os << "\n\n"; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1040 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1041 // The state for all is always supposed to be first in the list. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1042 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1043 for (octave_idx_type i = 1; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1044 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1045 std::string tid = ident(i).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1046 std::string tst = state(i).string_value (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1047 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1048 os << std::setw (7) << tst << " " << tid << "\n"; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1049 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1050 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1051 os << std::endl; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1052 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1053 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1054 void error_system::set_warning_option (const std::string& state, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1055 const std::string& ident) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1056 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1057 std::string all_state = default_warning_state (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1058 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1059 if (state != "on" && state != "off" && state != "error") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1060 error ("invalid warning state: %s", state.c_str ()); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1061 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1062 octave_map opts = warning_options (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1063 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1064 Cell tid = opts.contents ("identifier"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1065 Cell tst = opts.contents ("state"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1066 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1067 octave_idx_type nel = tid.numel (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1068 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1069 for (octave_idx_type i = 0; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1070 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1071 if (tid(i).string_value () == ident) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1072 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1073 // We found it in the current list of options. If the state |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1074 // for "all" is same as arg1, we can simply remove the item |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1075 // from the list. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1076 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1077 if (state == all_state && ident != "all") |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1078 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1079 for (i = i + 1; i < nel; i++) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1080 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1081 tid(i-1) = tid(i); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1082 tst(i-1) = tst(i); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1083 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1084 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1085 tid.resize (dim_vector (1, nel-1)); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1086 tst.resize (dim_vector (1, nel-1)); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1087 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1088 else |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1089 tst(i) = state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1090 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1091 opts.clear (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1092 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1093 opts.assign ("identifier", tid); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1094 opts.assign ("state", tst); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1095 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1096 warning_options (opts); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1097 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1098 return; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1099 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1100 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1101 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1102 // The option wasn't already in the list. Append it. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1103 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1104 tid.resize (dim_vector (1, nel+1)); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1105 tst.resize (dim_vector (1, nel+1)); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1106 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1107 tid(nel) = ident; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1108 tst(nel) = state; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1109 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1110 opts.clear (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1111 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1112 opts.assign ("identifier", tid); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1113 opts.assign ("state", tst); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1114 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1115 warning_options (opts); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1116 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1117 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1118 void error_system::disable_warning (const std::string& id) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1119 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1120 set_warning_option ("off", id); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1121 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1122 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1123 void error_system::initialize_default_warning_state (void) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1124 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1125 warning_options (octave::init_warning_options ("on")); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1126 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1127 // Most people will want to have the following disabled. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1128 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1129 disable_warning ("Octave:array-as-logical"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1130 disable_warning ("Octave:array-to-scalar"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1131 disable_warning ("Octave:array-to-vector"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1132 disable_warning ("Octave:imag-to-real"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1133 disable_warning ("Octave:language-extension"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1134 disable_warning ("Octave:missing-semicolon"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1135 disable_warning ("Octave:neg-dim-as-zero"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1136 disable_warning ("Octave:resize-on-range-error"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1137 disable_warning ("Octave:separator-insert"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1138 disable_warning ("Octave:single-quote-string"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1139 disable_warning ("Octave:str-to-num"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1140 disable_warning ("Octave:mixed-string-concat"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1141 disable_warning ("Octave:variable-switch-label"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1142 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1143 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1144 void error_system::interpreter_try (octave::unwind_protect& frame, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1145 try_option opt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1146 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1147 switch (opt) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1148 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1149 case buffer: |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1150 frame.protect_var (m_buffer_error_messages); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1151 m_buffer_error_messages++; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1152 break; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1153 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1154 case discard: |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1155 frame.protect_var (m_discard_error_messages); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1156 m_discard_error_messages = true; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1157 break; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1158 } |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1159 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1160 frame.protect_var (m_debug_on_error); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1161 m_debug_on_error = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1162 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1163 frame.protect_var (m_debug_on_warning); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1164 m_debug_on_warning = false; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1165 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1166 // Leave debug_on_caught as it was, so errors in try/catch are still |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1167 // caught. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1168 } |
19421
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
1169 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19415
diff
changeset
|
1170 |
23464
7eb0077e86f0
show stack trace for wrong type arg errors (bug #50894)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1171 octave::execution_exception |
20780
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1172 make_execution_exception (const char *who) |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1173 { |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1174 std::ostringstream buf; |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1175 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1176 pr_where (buf, who); |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1177 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1178 octave::execution_exception retval; |
20780
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1179 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1180 retval.set_stack_trace (buf.str ()); |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1181 |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1182 return retval; |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1183 } |
92958b1ee100
restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents:
20777
diff
changeset
|
1184 |
1 | 1185 void |
6338 | 1186 vmessage (const char *name, const char *fmt, va_list args) |
1187 { | |
1188 verror (false, std::cerr, name, "", fmt, args); | |
1189 } | |
1190 | |
1191 void | |
1 | 1192 message (const char *name, const char *fmt, ...) |
1193 { | |
1194 va_list args; | |
1195 va_start (args, fmt); | |
6338 | 1196 vmessage (name, fmt, args); |
1 | 1197 va_end (args); |
1198 } | |
1199 | |
1200 void | |
6338 | 1201 vmessage_with_id (const char *name, const char *id, const char *fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1202 va_list args) |
6338 | 1203 { |
1204 verror (false, std::cerr, name, id, fmt, args); | |
1205 } | |
1206 | |
1207 void | |
5567 | 1208 message_with_id (const char *name, const char *id, const char *fmt, ...) |
1209 { | |
1210 va_list args; | |
1211 va_start (args, fmt); | |
6338 | 1212 vmessage_with_id (name, id, fmt, args); |
5567 | 1213 va_end (args); |
1214 } | |
1215 | |
1216 void | |
6338 | 1217 vusage_with_id (const char *id, const char *fmt, va_list args) |
1218 { | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1219 octave::execution_exception e = make_execution_exception ("usage"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1220 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1221 vusage (e, id, fmt, args); |
6338 | 1222 } |
1223 | |
1224 void | |
5567 | 1225 usage_with_id (const char *id, const char *fmt, ...) |
1226 { | |
1227 va_list args; | |
1228 va_start (args, fmt); | |
6338 | 1229 vusage_with_id (id, fmt, args); |
1 | 1230 va_end (args); |
1231 } | |
1232 | |
6000 | 1233 void |
6338 | 1234 verror (const char *fmt, va_list args) |
1235 { | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1236 error_1 (std::cerr, "error", "", fmt, args); |
6338 | 1237 } |
1238 | |
1239 void | |
6000 | 1240 error (const char *fmt, ...) |
1241 { | |
1242 va_list args; | |
1243 va_start (args, fmt); | |
6338 | 1244 verror (fmt, args); |
6000 | 1245 va_end (args); |
1246 } | |
1247 | |
1248 void | |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1249 verror (octave::execution_exception& e, const char *fmt, va_list args) |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1250 { |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1251 error_1 (e, std::cerr, "error", "", fmt, args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1252 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1253 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1254 void |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1255 error (octave::execution_exception& e, const char *fmt, ...) |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1256 { |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1257 va_list args; |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1258 va_start (args, fmt); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1259 verror (e, fmt, args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1260 va_end (args); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1261 } |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1262 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1263 void |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1264 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
|
1265 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1266 error_1 (std::cerr, "error", "", fmt, args, true); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1267 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1268 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1269 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1270 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
|
1271 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1272 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1273 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1274 verror_with_cfn (fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1275 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1276 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1277 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1278 void |
6338 | 1279 verror_with_id (const char *id, const char *fmt, va_list args) |
1280 { | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1281 error_1 (std::cerr, "error", id, fmt, args); |
6338 | 1282 } |
1283 | |
1284 void | |
6000 | 1285 error_with_id (const char *id, const char *fmt, ...) |
1286 { | |
1287 va_list args; | |
1288 va_start (args, fmt); | |
6338 | 1289 verror_with_id (id, fmt, args); |
6000 | 1290 va_end (args); |
1291 } | |
1292 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1293 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1294 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
|
1295 { |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20511
diff
changeset
|
1296 error_1 (std::cerr, "error", id, fmt, args, true); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1297 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1298 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1299 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1300 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
|
1301 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1302 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1303 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1304 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
|
1305 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1306 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
1307 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1308 int warning_enabled (const std::string& id) |
1 | 1309 { |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1310 octave::error_system& es = octave::__get_error_system__ ("warning_enabled"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1311 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1312 return es.warning_enabled (id); |
1 | 1313 } |
1314 | |
1315 void | |
6338 | 1316 vwarning (const char *fmt, va_list args) |
1317 { | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1318 vwarning ("", fmt, args); |
6338 | 1319 } |
1320 | |
1321 void | |
5567 | 1322 warning (const char *fmt, ...) |
1323 { | |
1324 va_list args; | |
1325 va_start (args, fmt); | |
6338 | 1326 vwarning (fmt, args); |
5567 | 1327 va_end (args); |
1328 } | |
1329 | |
1330 void | |
6338 | 1331 vwarning_with_id (const char *id, const char *fmt, va_list args) |
1332 { | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1333 vwarning (id, fmt, args); |
6338 | 1334 } |
1335 | |
1336 void | |
5567 | 1337 warning_with_id (const char *id, const char *fmt, ...) |
1338 { | |
1339 va_list args; | |
1340 va_start (args, fmt); | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1341 vwarning (id, fmt, args); |
5567 | 1342 va_end (args); |
1343 } | |
1344 | |
1345 void | |
6338 | 1346 vparse_error (const char *fmt, va_list args) |
1347 { | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
1348 error_1 (std::cerr, nullptr, "", fmt, args); |
6338 | 1349 } |
1350 | |
1351 void | |
1005 | 1352 parse_error (const char *fmt, ...) |
1353 { | |
1354 va_list args; | |
1355 va_start (args, fmt); | |
6338 | 1356 vparse_error (fmt, args); |
5567 | 1357 va_end (args); |
1358 } | |
1359 | |
1360 void | |
6338 | 1361 vparse_error_with_id (const char *id, const char *fmt, va_list args) |
1362 { | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
1363 error_1 (std::cerr, nullptr, id, fmt, args); |
6338 | 1364 } |
1365 | |
1366 void | |
5567 | 1367 parse_error_with_id (const char *id, const char *fmt, ...) |
1368 { | |
1369 va_list args; | |
1370 va_start (args, fmt); | |
6338 | 1371 vparse_error_with_id (id, fmt, args); |
1 | 1372 va_end (args); |
1373 } | |
1374 | |
189 | 1375 void |
6361 | 1376 rethrow_error (const char *id, const char *fmt, ...) |
1377 { | |
1378 va_list args; | |
1379 va_start (args, fmt); | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
1380 error_1 (std::cerr, nullptr, id, fmt, args); |
6361 | 1381 va_end (args); |
1382 } | |
1383 | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1384 OCTAVE_NORETURN |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1385 void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1386 vpanic (const char *fmt, va_list args) |
22808
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1387 { |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1388 octave::error_system& es = octave::__get_error_system__ ("vpanic"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1389 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1390 es.vpanic (fmt, args); |
22808
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1391 } |
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1392 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1393 OCTAVE_NORETURN |
6361 | 1394 void |
1 | 1395 panic (const char *fmt, ...) |
1396 { | |
1397 va_list args; | |
1398 va_start (args, fmt); | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1399 vpanic (fmt, args); |
4732 | 1400 va_end (args); |
1401 } | |
1402 | |
1403 void | |
1404 defun_usage_message (const std::string& msg) | |
1405 { | |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1406 defun_usage_message ("%s", msg.c_str ()); |
528 | 1407 } |
1408 | |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1409 DEFMETHOD (rethrow, interp, args, , |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1410 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1411 @deftypefn {} {} rethrow (@var{err}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1412 Reissue a previous error as defined by @var{err}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1413 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1414 @var{err} is a structure that must contain at least the @qcode{"message"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1415 and @qcode{"identifier"} fields. @var{err} can also contain a field |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1416 @qcode{"stack"} that gives information on the assumed location of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1417 error. Typically @var{err} is returned from @code{lasterror}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1418 @seealso{lasterror, lasterr, error} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1419 @end deftypefn */) |
6361 | 1420 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20817
diff
changeset
|
1421 if (args.length () != 1) |
6959 | 1422 print_usage (); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1423 |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1424 const octave_scalar_map err = args(0).scalar_map_value (); |
6361 | 1425 |
22808
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1426 if (! (err.contains ("message") && err.contains ("identifier"))) |
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1427 error ("rethrow: ERR struct must contain the fields 'message' and 'identifier'"); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1428 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1429 std::string msg = err.contents ("message").string_value (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1430 std::string id = err.contents ("identifier").string_value (); |
6483 | 1431 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1432 octave_map err_stack = octave::init_error_stack (interp); |
6483 | 1433 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1434 if (err.contains ("stack")) |
22808
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1435 err_stack = err.contents ("stack").xmap_value ("ERR.STACK must be a struct"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1436 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1437 octave::error_system& es = interp.get_error_system (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1438 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1439 es.rethrow_error (id, msg, err_stack); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1440 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1441 return ovl (); |
6361 | 1442 } |
1443 | |
1957 | 1444 DEFUN (error, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1445 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1446 @deftypefn {} {} error (@var{template}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1447 @deftypefnx {} {} error (@var{id}, @var{template}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1448 Display an error message and stop m-file execution. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1449 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1450 Format the optional arguments under the control of the template string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1451 @var{template} using the same rules as the @code{printf} family of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1452 functions (@pxref{Formatted Output}) and print the resulting message |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1453 on the @code{stderr} stream. The message is prefixed by the character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1454 string @samp{error: }. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1455 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1456 Calling @code{error} also sets Octave's internal error state such that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1457 control will return to the top level without evaluating any further |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1458 commands. This is useful for aborting from functions or scripts. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1459 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1460 If the error message does not end with a newline character, Octave will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1461 print a traceback of all the function calls leading to the error. For |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1462 example, given the following function definitions: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1463 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1464 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1465 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1466 function f () g (); end |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1467 function g () h (); end |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1468 function h () nargin == 1 || error ("nargin != 1"); end |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1469 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1470 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1471 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1472 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1473 calling the function @code{f} will result in a list of messages that |
22808
1d3d0321bc5d
preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
1474 can help you to quickly find the exact location of the error: |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1475 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1476 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1477 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1478 f () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1479 error: nargin != 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1480 error: called from: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1481 error: h at line 1, column 27 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1482 error: g at line 1, column 15 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1483 error: f at line 1, column 15 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1484 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1485 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1486 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1487 If the error message ends in a newline character, Octave will print the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1488 message but will not display any traceback messages as it returns |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1489 control to the top level. For example, modifying the error message |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1490 in the previous example to end in a newline causes Octave to only print |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1491 a single message: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1492 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1493 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1494 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1495 function h () nargin == 1 || error ("nargin != 1\n"); end |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1496 f () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1497 error: nargin != 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1498 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1499 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1500 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1501 A null string ("") input to @code{error} will be ignored and the code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1502 will continue running as if the statement were a NOP@. This is for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1503 compatibility with @sc{matlab}. It also makes it possible to write code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1504 such as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1505 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1506 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1507 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1508 err_msg = ""; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1509 if (CONDITION 1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1510 err_msg = "CONDITION 1 found"; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1511 elseif (CONDITION2) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1512 err_msg = "CONDITION 2 found"; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1513 @dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1514 endif |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1515 error (err_msg); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1516 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1517 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1518 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1519 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1520 which will only stop execution if an error has been found. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1521 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1522 Implementation Note: For compatibility with @sc{matlab}, escape |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1523 sequences in @var{template} (e.g., @qcode{"@xbackslashchar{}n"} => |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1524 newline) are processed regardless of whether @var{template} has been defined |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1525 with single quotes, as long as there are two or more input arguments. To |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1526 disable escape sequence expansion use a second backslash before the sequence |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1527 (e.g., @qcode{"@xbackslashchar{}@xbackslashchar{}n"}) or use the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1528 @code{regexptranslate} function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1529 @seealso{warning, lasterror} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1530 @end deftypefn */) |
897 | 1531 { |
7252 | 1532 |
1533 int nargin = args.length (); | |
1534 | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1535 if (nargin == 0) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1536 print_usage (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1537 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1538 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1539 |
7252 | 1540 octave_value_list nargs = args; |
1541 | |
1542 std::string id; | |
1543 | |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1544 bool have_fmt = false; |
5567 | 1545 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1546 if (nargin == 1 && args(0).isstruct ()) |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1547 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1548 // empty struct is not an error. return and resume calling function. |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
1549 if (args(0).isempty ()) |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1550 return retval; |
13709
a0875c6cab7e
error.cc: Don't complain if error struct input is empty (Matlab compatability)
Rik <octave@nomad.inbox5.com>
parents:
12705
diff
changeset
|
1551 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1552 octave_scalar_map m = args(0).scalar_map_value (); |
7252 | 1553 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1554 // empty struct is not an error. return and resume calling function. |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1555 if (m.nfields () == 0) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1556 return retval; |
7252 | 1557 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1558 if (m.contains ("message")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1559 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1560 octave_value c = m.getfield ("message"); |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1561 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1562 if (c.is_string ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1563 nargs(0) = c.string_value (); |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1564 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1565 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1566 if (m.contains ("identifier")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1567 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1568 octave_value c = m.getfield ("identifier"); |
7252 | 1569 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1570 if (c.is_string ()) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1571 id = c.string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1572 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1573 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1574 // FIXME: also need to handle "stack" field in error structure, |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1575 // but that will require some more significant surgery on |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1576 // handle_message, error_with_id, etc. |
7252 | 1577 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1578 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1579 have_fmt = maybe_extract_message_id ("error", args, nargs, id); |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1580 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1581 handle_message (error_with_id, id.c_str (), "unspecified error", |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1582 nargs, have_fmt); |
7252 | 1583 |
3934 | 1584 return retval; |
1489 | 1585 } |
897 | 1586 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
1587 DEFMETHOD (warning, interp, args, nargout, |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
1588 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1589 @deftypefn {} {} warning (@var{template}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1590 @deftypefnx {} {} warning (@var{id}, @var{template}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1591 @deftypefnx {} {} warning ("on", @var{id}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1592 @deftypefnx {} {} warning ("off", @var{id}) |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1593 @deftypefnx {} {} warning ("error", @var{id}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1594 @deftypefnx {} {} warning ("query", @var{id}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1595 @deftypefnx {} {} warning (@var{state}, @var{id}, "local") |
25215
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1596 @deftypefnx {} {} warning (@var{warning_struct}) |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1597 @deftypefnx {} {@var{warning_struct} =} warning (@dots{}) |
25588
5f63ca41eacb
doc: Remove bad calling convention for warning with a mode struct (bug #54288)
Rik <rik@octave.org>
parents:
25579
diff
changeset
|
1598 @deftypefnx {} {} warning (@var{state}, @var{mode}) |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1599 |
25215
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1600 Display a warning message or control the behavior of Octave's warning system. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1601 |
25215
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1602 The first call form uses a template @var{template} and optional additional |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1603 arguments to display a message on the @code{stderr} stream. The message is |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1604 formatted using the same rules as the @code{printf} family of functions |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1605 (@pxref{Formatted Output}) and prefixed by the character string |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1606 @w{@samp{warning: }}. You should use this function when you want to notify the |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1607 user of an unusual condition, but only when it makes sense for your program to |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1608 go on. For example: |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1609 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1610 @example |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1611 @group |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1612 warning ("foo: maybe something wrong here"); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1613 @end group |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1614 @end example |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1615 |
26859
b4a9888bb3c9
doc: document the newline character in warning messages (bug #49158)
Mike Miller <mtmiller@octave.org>
parents:
26617
diff
changeset
|
1616 If the warning message does not end with a newline character, Octave will |
b4a9888bb3c9
doc: document the newline character in warning messages (bug #49158)
Mike Miller <mtmiller@octave.org>
parents:
26617
diff
changeset
|
1617 print a traceback of all the function calls leading to the warning. If the |
b4a9888bb3c9
doc: document the newline character in warning messages (bug #49158)
Mike Miller <mtmiller@octave.org>
parents:
26617
diff
changeset
|
1618 warning message does end in a newline character, Octave will suppress the |
b4a9888bb3c9
doc: document the newline character in warning messages (bug #49158)
Mike Miller <mtmiller@octave.org>
parents:
26617
diff
changeset
|
1619 traceback messages as it returns control to the top level. For more details |
b4a9888bb3c9
doc: document the newline character in warning messages (bug #49158)
Mike Miller <mtmiller@octave.org>
parents:
26617
diff
changeset
|
1620 and examples, see @ref{XREFerror,,error}. |
b4a9888bb3c9
doc: document the newline character in warning messages (bug #49158)
Mike Miller <mtmiller@octave.org>
parents:
26617
diff
changeset
|
1621 |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1622 The optional warning identifier @var{id} allows users to enable or disable |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1623 warnings tagged by this identifier. A message identifier is a string of the |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1624 form @qcode{"NAMESPACE:WARNING-NAME"}. Octave's own warnings use the |
24441 | 1625 @qcode{"Octave"} namespace (@pxref{XREFwarning_ids,,warning_ids}). For |
1626 example: | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1627 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1628 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1629 @group |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1630 warning ("MyNameSpace:check-something", |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1631 "foo: maybe something wrong here"); |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1632 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1633 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1634 |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1635 The second call form is meant to change and/or query the state of warnings. |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1636 The first input argument must be a string @var{state} (@qcode{"on"}, |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1637 @qcode{"off"}, @qcode{"error"}, or @qcode{"query"}) followed by an optional |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1638 warning identifier @var{id} or @qcode{"all"} (default). |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1639 |
25215
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1640 The optional output argument @var{warning_struct} is a structure or structure |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1641 array with fields @qcode{"state"} and @qcode{"identifier"}. The @var{state} |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1642 argument may have the following values: |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1643 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1644 @table @asis |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1645 @item @qcode{"on"}|@qcode{"off"}: |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1646 Enable or disable the display of warnings identified by @var{id} and optionally |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1647 return their previous state @var{stout}. |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1648 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1649 @item @qcode{"error"}: |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1650 Turn warnings identified by @var{id} into errors and optionally return their |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1651 previous state @var{stout}. |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1652 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1653 @item @qcode{"query"}: |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1654 Return the current state of warnings identified by @var{id}. |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1655 @end table |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1656 |
25215
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1657 A structure or structure array @var{warning_struct}, with fields |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1658 @qcode{"state"} and @qcode{"identifier"}, may be given as an input to achieve |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1659 equivalent results. The following example shows how to temporarily disable a |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1660 warning and then restore its original state: |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1661 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1662 @example |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1663 @group |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1664 loglog (-1:10); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1665 ## Disable the previous warning and save its original state |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1666 [~, id] = lastwarn (); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1667 warnstate = warning ("off", id); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1668 loglog (-1:10); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1669 ## Restore its original state |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1670 warning (warnstate); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1671 @end group |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1672 @end example |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1673 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1674 If a final argument @qcode{"local"} is provided then the warning state will be |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1675 set temporarily until the end of the current function. Changes to warning |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1676 states that are set locally affect the current function and all functions |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1677 called from the current scope. The previous warning state is restored on |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1678 return from the current function. The @qcode{"local"} option is ignored if |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1679 used in the top-level workspace. |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1680 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1681 With no input argument @code{warning ()} is equivalent to |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1682 @code{warning ("query", "all")} except that in the absence of an output |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1683 argument, the state of warnings is displayed on @code{stderr}. |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1684 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1685 The level of verbosity of the warning system may also be controlled by two |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1686 modes @var{mode}: |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1687 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1688 @table @asis |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1689 @item @qcode{"backtrace"}: |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1690 enable/disable the display of the stack trace after the warning message |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1691 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1692 @item @qcode{"verbose"}: |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1693 enable/disable the display of additional information after the warning message |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1694 @end table |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1695 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1696 In this case the @var{state} argument may only be @qcode{"on"} or |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1697 @qcode{"off"}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1698 |
25215
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1699 Implementation Note: For compatibility with @sc{matlab}, escape sequences in |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1700 @var{template} (e.g., @qcode{"@xbackslashchar{}n"} => newline) are processed |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1701 regardless of whether @var{template} has been defined with single quotes, as |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1702 long as there are two or more input arguments. To disable escape sequence |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1703 expansion use a second backslash before the sequence (e.g., |
7ca5f8c70879
doc: Update docstring for warning().
Rik <rik@octave.org>
parents:
25164
diff
changeset
|
1704 @qcode{"@xbackslashchar{}@xbackslashchar{}n"}) or use the |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1705 @code{regexptranslate} function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1706 @seealso{warning_ids, lastwarn, error} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
1707 @end deftypefn */) |
1489 | 1708 { |
5567 | 1709 octave_value retval; |
3934 | 1710 |
5567 | 1711 int nargin = args.length (); |
3935 | 1712 bool done = false; |
3934 | 1713 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1714 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1715 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1716 if (nargin > 0 && args.all_strings_p ()) |
3935 | 1717 { |
1718 string_vector argv = args.make_argv ("warning"); | |
1719 | |
20996 | 1720 std::string arg1 = argv[1]; |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1721 std::string arg2 = "all"; |
5567 | 1722 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1723 if (nargin >= 2) |
20996 | 1724 arg2 = argv[2]; |
5567 | 1725 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1726 if (arg1 == "on" || arg1 == "off" || arg1 == "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1727 { |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1728 // Prepare output structure |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1729 octave_map old_warning_options; |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1730 if (arg2 == "all") |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1731 old_warning_options = es.warning_options (); |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1732 else |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1733 old_warning_options = octave_map (es.warning_query (arg2)); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1734 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26619
diff
changeset
|
1735 if (nargin == 3 && argv[3] == "local" && ! interp.at_top_level ()) |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1736 { |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1737 octave_scalar_map val = es.warning_query (arg2); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1738 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1739 octave_value curr_state = val.contents ("state"); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1740 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1741 // FIXME: this might be better with a dictionary object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1742 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26619
diff
changeset
|
1743 octave::tree_evaluator& tw = interp.get_evaluator (); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26619
diff
changeset
|
1744 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1745 octave_value curr_warning_states |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26619
diff
changeset
|
1746 = tw.get_auto_fcn_var (octave::stack_frame::SAVED_WARNING_STATES); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1747 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1748 octave_map m; |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1749 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1750 if (curr_warning_states.is_defined ()) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1751 m = curr_warning_states.map_value (); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1752 else |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1753 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1754 string_vector fields (2); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1755 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1756 fields(0) = "identifier"; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1757 fields(1) = "state"; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1758 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1759 m = octave_map (dim_vector (0, 1), fields); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1760 } |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1761 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1762 Cell ids = m.contents ("identifier"); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1763 Cell states = m.contents ("state"); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1764 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1765 octave_idx_type nel = states.numel (); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1766 bool found = false; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1767 octave_idx_type i; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1768 for (i = 0; i < nel; i++) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1769 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1770 std::string id = ids(i).string_value (); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1771 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1772 if (id == arg2) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1773 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1774 states(i) = curr_state; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1775 found = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1776 break; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1777 } |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1778 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1779 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1780 if (! found) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1781 { |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1782 m.resize (dim_vector (nel+1, 1)); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1783 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1784 ids.resize (dim_vector (nel+1, 1)); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1785 states.resize (dim_vector (nel+1, 1)); |
3934 | 1786 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1787 ids(nel) = arg2; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1788 states(nel) = curr_state; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1789 } |
7202 | 1790 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1791 m.contents ("identifier") = ids; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1792 m.contents ("state") = states; |
7202 | 1793 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26619
diff
changeset
|
1794 tw.set_auto_fcn_var (octave::stack_frame::SAVED_WARNING_STATES, m); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1795 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1796 // Now ignore the "local" argument and continue to |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1797 // handle the current setting. |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1798 nargin--; |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1799 } |
7202 | 1800 |
21000 | 1801 if (nargin >= 2 && arg2 == "all") |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1802 { |
21000 | 1803 // If "all" is explicitly given as ID. |
7202 | 1804 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1805 octave_map tmp; |
22223
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1806 int is_error = (arg1 == "error"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1807 |
22223
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1808 Cell id (1, 1 + 2*is_error); |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1809 Cell st (1, 1 + 2*is_error); |
7206 | 1810 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1811 id(0) = arg2; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1812 st(0) = arg1; |
7206 | 1813 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1814 // Since internal Octave functions are not compatible, |
22223
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1815 // and "all"=="error" causes any "on" to throw an error, |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1816 // turning all warnings into errors should disable |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1817 // Octave:language-extension. |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1818 |
22223
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1819 if (is_error) |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1820 { |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1821 id(1) = "Octave:language-extension"; |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1822 st(1) = "off"; |
7202 | 1823 |
22223
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1824 id(2) = "Octave:single-quote-string"; |
cf18d6e791a1
Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22196
diff
changeset
|
1825 st(2) = "off"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1826 } |
5567 | 1827 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1828 tmp.assign ("identifier", id); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1829 tmp.assign ("state", st); |
5582 | 1830 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1831 es.warning_options (tmp); |
5567 | 1832 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1833 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1834 } |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1835 else if (arg2 == "backtrace") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1836 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1837 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1838 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1839 es.backtrace_on_warning (arg1 == "on"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1840 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1841 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1842 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1843 else if (arg2 == "debug") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1844 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1845 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1846 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1847 es.debug_on_warning (arg1 == "on"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1848 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1849 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1850 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1851 else if (arg2 == "verbose") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1852 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1853 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1854 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1855 es.verbose_warning (arg1 == "on"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1856 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1857 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1858 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1859 else if (arg2 == "quiet") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1860 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1861 if (arg1 != "error") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1862 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1863 es.quiet_warning (arg1 == "on"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1864 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1865 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1866 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1867 else |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1868 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1869 if (arg2 == "last") |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1870 arg2 = es.last_warning_id (); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1871 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1872 es.set_warning_option (arg1, arg2); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1873 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1874 done = true; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1875 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1876 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1877 if (done && nargout > 0) |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1878 retval = old_warning_options; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1879 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1880 else if (arg1 == "query") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1881 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1882 if (arg2 == "all") |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1883 retval = es.warning_options (); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1884 else if (arg2 == "backtrace" || arg2 == "debug" |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1885 || arg2 == "verbose" || arg2 == "quiet") |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1886 { |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1887 octave_scalar_map tmp; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1888 tmp.assign ("identifier", arg2); |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1889 if (arg2 == "backtrace") |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1890 tmp.assign ("state", es.backtrace_on_warning () ? "on" : "off"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1891 else if (arg2 == "debug") |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1892 tmp.assign ("state", es.debug_on_warning () ? "on" : "off"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1893 else if (arg2 == "verbose") |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1894 tmp.assign ("state", es.verbose_warning () ? "on" : "off"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1895 else |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1896 tmp.assign ("state", es.quiet_warning () ? "on" : "off"); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1897 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1898 retval = tmp; |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1899 } |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1900 else |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1901 retval = es.warning_query (arg2); |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1902 |
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1903 done = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1904 } |
3934 | 1905 } |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1906 else if (nargin == 0) |
5567 | 1907 { |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1908 if (nargout > 0) |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1909 retval = es.warning_options (); |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1910 else |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1911 es.display_warning_options (octave_stdout); |
3934 | 1912 |
5567 | 1913 done = true; |
1914 } | |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1915 else if (nargin == 1) |
5567 | 1916 { |
1917 octave_value arg = args(0); | |
1918 | |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1919 octave_map old_warning_options; |
5567 | 1920 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1921 if (arg.isstruct ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1922 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1923 octave_map m = arg.map_value (); |
5567 | 1924 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1925 if (! m.contains ("identifier") || ! m.contains ("state")) |
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1926 error ("warning: STATE structure must have fields 'identifier' and 'state'"); |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1927 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1928 // Simply step through the struct elements one at a time. |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1929 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1930 Cell ident = m.contents ("identifier"); |
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1931 Cell state = m.contents ("state"); |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1932 |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1933 octave_idx_type nel = ident.numel (); |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1934 |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1935 // Prepare output structure |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1936 old_warning_options = octave_map (m); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1937 Cell oldstate (state); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1938 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1939 for (octave_idx_type i = 0; i < nel; i++) |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1940 { |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1941 std::string tid = ident(i).string_value (); |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1942 oldstate(i) = es.warning_query (tid).getfield ("state"); |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1943 } |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1944 old_warning_options.setfield ("state", oldstate); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1945 |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1946 // Set new values |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1947 for (octave_idx_type i = 0; i < nel; i++) |
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1948 { |
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1949 std::string tst = state(i).string_value (); |
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1950 std::string tid = ident(i).string_value (); |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1951 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
1952 es.set_warning_option (tst, tid); |
19439
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19421
diff
changeset
|
1953 } |
5567 | 1954 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1955 done = true; |
5567 | 1956 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1957 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1958 retval = old_warning_options; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1959 } |
5567 | 1960 } |
1961 | |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
1962 if (! done) |
3935 | 1963 { |
5567 | 1964 octave_value_list nargs = args; |
1965 | |
1966 std::string id; | |
1967 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1968 bool have_fmt = maybe_extract_message_id ("warning", args, nargs, id); |
5567 | 1969 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
1970 std::string prev_msg = es.last_warning_message (); |
3935 | 1971 |
5567 | 1972 std::string curr_msg = handle_message (warning_with_id, id.c_str (), |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1973 "unspecified warning", nargs, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1974 have_fmt); |
3935 | 1975 |
1976 if (nargout > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1977 retval = prev_msg; |
3935 | 1978 } |
1979 | |
3934 | 1980 return retval; |
1981 } | |
1982 | |
20963
6ed7bae8017b
Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20181
diff
changeset
|
1983 /* |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1984 %!test <*45753> |
20963
6ed7bae8017b
Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20181
diff
changeset
|
1985 %! warning ("error"); |
6ed7bae8017b
Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20181
diff
changeset
|
1986 %! assert (! isempty (help ("warning"))); |
6ed7bae8017b
Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20181
diff
changeset
|
1987 */ |
6ed7bae8017b
Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20181
diff
changeset
|
1988 |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1989 /* |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1990 %!test <*51997> |
26596
cc0d942d0e20
Remove inconsistent warning "Octave:divide-by-zero" (bug #46650).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
26376
diff
changeset
|
1991 %! id = "Octave:logical-conversion"; |
24047
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1992 %! current = warning ("query", id); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1993 %! current_all = warning (); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1994 %! previous = warning (current_all); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1995 %! assert (previous, current_all); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1996 %! previous = warning (current); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1997 %! assert (previous, current); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1998 %! previous = warning (current.state, id); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
1999 %! assert (previous, current); |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
2000 */ |
9c198d1c84cd
Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23850
diff
changeset
|
2001 |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2002 octave_value_list |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2003 set_warning_state (const std::string& id, const std::string& state) |
5794 | 2004 { |
2005 octave_value_list args; | |
2006 | |
2007 args(1) = id; | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2008 args(0) = state; |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2009 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2010 octave::interpreter& interp |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2011 = octave::__get_interpreter__ ("set_warning_state"); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2012 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2013 return Fwarning (interp, args, 1); |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2014 } |
5794 | 2015 |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2016 octave_value_list |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2017 set_warning_state (const octave_value_list& args) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2018 { |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2019 octave::interpreter& interp |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2020 = octave::__get_interpreter__ ("set_warning_state"); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2021 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2022 return Fwarning (interp, args, 1); |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2023 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2024 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2025 void |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2026 disable_warning (const std::string& id) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
2027 { |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2028 octave::error_system& es = octave::__get_error_system__ ("disable_warning"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2029 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2030 es.disable_warning (id); |
5794 | 2031 } |
2032 | |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2033 DEFMETHOD (lasterror, interp, args, , |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23465
diff
changeset
|
2034 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2035 @deftypefn {} {@var{lasterr} =} lasterror () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2036 @deftypefnx {} {} lasterror (@var{err}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2037 @deftypefnx {} {} lasterror ("reset") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2038 Query or set the last error message structure. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2039 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2040 When called without arguments, return a structure containing the last error |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2041 message and other information related to this error. The elements of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2042 structure are: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2043 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2044 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2045 @item message |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2046 The text of the last error message |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2047 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2048 @item identifier |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2049 The message identifier of this error message |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2050 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2051 @item stack |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2052 A structure containing information on where the message occurred. This may |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2053 be an empty structure if the information cannot be obtained. The fields of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2054 the structure are: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2055 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2056 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2057 @item file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2058 The name of the file where the error occurred |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2059 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2060 @item name |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2061 The name of function in which the error occurred |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2062 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2063 @item line |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2064 The line number at which the error occurred |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2065 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2066 @item column |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2067 An optional field with the column number at which the error occurred |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2068 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2069 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2070 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2071 The last error structure may be set by passing a scalar structure, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2072 @var{err}, as input. Any fields of @var{err} that match those above are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2073 set while any unspecified fields are initialized with default values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2074 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2075 If @code{lasterror} is called with the argument @qcode{"reset"}, all |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2076 fields are set to their default values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2077 @seealso{lasterr, error, lastwarn} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2078 @end deftypefn */) |
6361 | 2079 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
2080 int nargin = args.length (); |
6361 | 2081 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2082 if (nargin > 1) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2083 print_usage (); |
6361 | 2084 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2085 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2086 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2087 octave_scalar_map err; |
6361 | 2088 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2089 err.assign ("message", es.last_error_message ()); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2090 err.assign ("identifier", es.last_error_id ()); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2091 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2092 err.assign ("stack", octave_value (es.last_error_stack ())); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
2093 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2094 if (nargin == 1) |
6361 | 2095 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2096 octave::call_stack& cs = interp.get_call_stack (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2097 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2098 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2099 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2100 if (args(0).string_value () != "reset") |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20946
diff
changeset
|
2101 error ("lasterror: unrecognized string argument"); |
6361 | 2102 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2103 es.last_error_message (""); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2104 es.last_error_id (""); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2105 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2106 es.last_error_stack (cs.empty_backtrace ()); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2107 } |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
2108 else if (args(0).isstruct ()) |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2109 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2110 octave_scalar_map new_err = args(0).scalar_map_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2111 octave_scalar_map new_err_stack; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2112 std::string new_error_message; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2113 std::string new_error_id; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2114 std::string new_error_file; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2115 std::string new_error_name; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2116 int new_error_line = -1; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2117 int new_error_column = -1; |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2118 bool initialize_stack = false; |
6361 | 2119 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2120 if (new_err.contains ("message")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2121 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2122 const std::string tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2123 new_err.getfield ("message").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2124 new_error_message = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2125 } |
6361 | 2126 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2127 if (new_err.contains ("identifier")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2128 { |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2129 const std::string tmp = |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2130 new_err.getfield ("identifier").string_value (); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2131 new_error_id = tmp; |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2132 } |
6361 | 2133 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2134 if (new_err.contains ("stack")) |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2135 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
2136 if (new_err.getfield ("stack").isempty ()) |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2137 initialize_stack = true; |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2138 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2139 { |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2140 new_err_stack = |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2141 new_err.getfield ("stack").scalar_map_value (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2142 |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2143 if (new_err_stack.contains ("file")) |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2144 { |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2145 const std::string tmp = |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2146 new_err_stack.getfield ("file").string_value (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2147 new_error_file = tmp; |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2148 } |
6361 | 2149 |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2150 if (new_err_stack.contains ("name")) |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2151 { |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2152 const std::string tmp = |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2153 new_err_stack.getfield ("name").string_value (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2154 new_error_name = tmp; |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2155 } |
6361 | 2156 |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2157 if (new_err_stack.contains ("line")) |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2158 { |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2159 const int tmp = |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2160 new_err_stack.getfield ("line").nint_value (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2161 new_error_line = tmp; |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2162 } |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2163 |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2164 if (new_err_stack.contains ("column")) |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2165 { |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2166 const int tmp = |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2167 new_err_stack.getfield ("column").nint_value (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2168 new_error_column = tmp; |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2169 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2170 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2171 } |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2172 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2173 es.last_error_message (new_error_message); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2174 es.last_error_id (new_error_id); |
6361 | 2175 |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2176 if (initialize_stack) |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2177 es.last_error_stack (cs.empty_backtrace ()); |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2178 else if (new_err.contains ("stack")) |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2179 { |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2180 new_err_stack.setfield ("file", new_error_file); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2181 new_err_stack.setfield ("name", new_error_name); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2182 new_err_stack.setfield ("line", new_error_line); |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2183 new_err_stack.setfield ("column", new_error_column); |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2184 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2185 es.last_error_stack (new_err_stack); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2186 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2187 else |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2188 es.last_error_stack (cs.backtrace ()); |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2189 } |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2190 else |
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2191 error ("lasterror: argument must be a structure or a string"); |
6361 | 2192 } |
2193 | |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2194 return ovl (err); |
6361 | 2195 } |
2196 | |
21856
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2197 /* |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2198 ## Test lasterror with empty error state |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2199 %!test |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2200 %! lasterror ("reset"); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2201 %! x = lasterror (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2202 %! assert (x.identifier, "") |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2203 %! assert (x.message, "") |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2204 %! assert (isempty (x.stack)) |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2205 %! lasterror (x); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2206 %! y = lasterror (); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2207 %! assert (y, x); |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2208 */ |
c9c5340d4758
lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents:
21751
diff
changeset
|
2209 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2210 DEFMETHOD (lasterr, interp, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2211 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2212 @deftypefn {} {[@var{msg}, @var{msgid}] =} lasterr () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2213 @deftypefnx {} {} lasterr (@var{msg}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2214 @deftypefnx {} {} lasterr (@var{msg}, @var{msgid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2215 Query or set the last error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2216 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2217 When called without input arguments, return the last error message and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2218 message identifier. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2219 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2220 With one argument, set the last error message to @var{msg}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2221 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2222 With two arguments, also set the last message identifier. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2223 @seealso{lasterror, error, lastwarn} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2224 @end deftypefn */) |
3935 | 2225 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2226 int nargin = args.length (); |
3935 | 2227 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2228 if (nargin > 2) |
5823 | 2229 print_usage (); |
3935 | 2230 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2231 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2232 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2233 string_vector argv = args.make_argv ("lasterr"); |
5567 | 2234 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2235 std::string prev_error_id = es.last_error_id (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2236 std::string prev_error_message = es.last_error_message (); |
5567 | 2237 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2238 if (nargin == 2) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2239 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2240 es.last_error_id (argv[2]); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2241 es.last_error_message (argv[1]); |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2242 } |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2243 else if (nargin == 1) |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2244 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2245 es.last_error_id (""); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2246 es.last_error_message (argv[1]); |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2247 } |
5567 | 2248 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2249 if (nargin == 0 || nargout > 0) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2250 return ovl (prev_error_message, prev_error_id); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2251 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
2252 return ovl (); |
3935 | 2253 } |
2254 | |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2255 DEFMETHOD (lastwarn, interp, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2256 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2257 @deftypefn {} {[@var{msg}, @var{msgid}] =} lastwarn () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2258 @deftypefnx {} {} lastwarn (@var{msg}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2259 @deftypefnx {} {} lastwarn (@var{msg}, @var{msgid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2260 Query or set the last warning message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2261 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2262 When called without input arguments, return the last warning message and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2263 message identifier. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2264 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2265 With one argument, set the last warning message to @var{msg}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2266 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2267 With two arguments, also set the last message identifier. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2268 @seealso{warning, lasterror, lasterr} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2269 @end deftypefn */) |
3934 | 2270 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2271 int nargin = args.length (); |
5567 | 2272 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2273 if (nargin > 2) |
5823 | 2274 print_usage (); |
3934 | 2275 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2276 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2277 |
20803
c22206c1a88f
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2278 string_vector argv = args.make_argv ("lastwarn"); |
5567 | 2279 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2280 std::string prev_warning_id = es.last_warning_id (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2281 std::string prev_warning_message = es.last_warning_message (); |
3934 | 2282 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2283 if (nargin == 2) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2284 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2285 es.last_warning_id (argv[2]); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2286 es.last_warning_message (argv[1]); |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2287 } |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2288 else if (nargin == 1) |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2289 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2290 es.last_warning_id (""); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2291 es.last_warning_message (argv[1]); |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2292 } |
5567 | 2293 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20803
diff
changeset
|
2294 if (nargin == 0 || nargout > 0) |
20828
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2295 return ovl (prev_warning_message, prev_warning_id); |
7883f240d8ea
Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents:
20827
diff
changeset
|
2296 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
2297 return ovl (); |
897 | 2298 } |
2299 | |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2300 DEFMETHOD (beep_on_error, interp, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2301 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2302 @deftypefn {} {@var{val} =} beep_on_error () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2303 @deftypefnx {} {@var{old_val} =} beep_on_error (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2304 @deftypefnx {} {} beep_on_error (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2305 Query or set the internal variable that controls whether Octave will try |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2306 to ring the terminal bell before printing an error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2307 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2308 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2309 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2310 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2311 @end deftypefn */) |
3707 | 2312 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2313 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2314 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2315 return es.beep_on_error (args, nargout); |
3707 | 2316 } |
2317 | |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2318 DEFMETHOD (debug_on_error, interp, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2319 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2320 @deftypefn {} {@var{val} =} debug_on_error () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2321 @deftypefnx {} {@var{old_val} =} debug_on_error (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2322 @deftypefnx {} {} debug_on_error (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2323 Query or set the internal variable that controls whether Octave will try |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2324 to enter the debugger when an error is encountered. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2325 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2326 This will also inhibit printing of the normal traceback message (you will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2327 only see the top-level error message). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2328 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2329 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2330 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2331 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2332 @seealso{debug_on_warning, debug_on_interrupt} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2333 @end deftypefn */) |
5794 | 2334 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2335 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2336 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2337 return es.debug_on_error (args, nargout); |
5794 | 2338 } |
3707 | 2339 |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2340 DEFMETHOD (debug_on_warning, interp, args, nargout, |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2341 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2342 @deftypefn {} {@var{val} =} debug_on_warning () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2343 @deftypefnx {} {@var{old_val} =} debug_on_warning (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2344 @deftypefnx {} {} debug_on_warning (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2345 Query or set the internal variable that controls whether Octave will try |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2346 to enter the debugger when a warning is encountered. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2347 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2348 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2349 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2350 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2351 @seealso{debug_on_error, debug_on_interrupt} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
2352 @end deftypefn */) |
5794 | 2353 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2354 octave::error_system& es = interp.get_error_system (); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2355 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2356 return es.debug_on_warning (args, nargout); |
2174 | 2357 } |
2358 | |
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
|
2359 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
|
2360 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
|
2361 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2362 octave::error_system& es |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2363 = octave::__get_error_system__ ("last_error_message"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2364 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2365 return es.last_error_message (); |
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
|
2366 } |
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
|
2367 |
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
|
2368 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
|
2369 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
|
2370 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2371 octave::error_system& es |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2372 = octave::__get_error_system__ ("last_error_id"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2373 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2374 return es.last_error_id (); |
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
|
2375 } |
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
|
2376 |
18222
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2377 octave_map |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2378 last_error_stack (void) |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2379 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2380 octave::error_system& es |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2381 = octave::__get_error_system__ ("last_error_stack"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2382 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2383 return es.last_error_stack (); |
18222
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2384 } |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18130
diff
changeset
|
2385 |
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
|
2386 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
|
2387 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
|
2388 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2389 octave::error_system& es |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2390 = octave::__get_error_system__ ("last_warning_message"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2391 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2392 return es.last_warning_message (); |
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
|
2393 } |
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
|
2394 |
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
|
2395 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
|
2396 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
|
2397 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2398 octave::error_system& es |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2399 = octave::__get_error_system__ ("last_warning_id"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2400 |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2401 return es.last_warning_id (); |
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
|
2402 } |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2403 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2404 void |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2405 interpreter_try (octave::unwind_protect& frame, |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2406 octave::error_system::try_option opt) |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2407 { |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2408 octave::error_system& es |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2409 = octave::__get_error_system__ ("interpreter_try"); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
27037
diff
changeset
|
2410 |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2411 es.interpreter_try (frame, opt); |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2412 } |
27161
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2413 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2414 // Deprecated variables and functions. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2415 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2416 // This variable is obsolete and always has the value 0. |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2417 int error_state = 0; |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2418 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2419 void |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2420 reset_error_handler (void) |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2421 { |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2422 octave::error_system& es |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2423 = octave::__get_error_system__ ("reset_error_handler"); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2424 |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2425 es.reset (); |
7883e6e71b0a
additional refactoring of error handling functions
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
2426 } |