annotate libinterp/corefcn/error.cc @ 25588:5f63ca41eacb stable

doc: Remove bad calling convention for warning with a mode struct (bug #54288) * error.cc (Fwarning): Remove "warning (mode_struct)" calling form which is not valid.
author Rik <rik@octave.org>
date Thu, 12 Jul 2018 09:13:59 -0700
parents 07c2c42f457e
children 053502516f38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24738
diff changeset
3 Copyright (C) 1993-2018 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1315
diff changeset
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
4a4440aa1262 [project @ 1995-11-14 23:01:31 by jwe]
jwe
parents: 1489
diff changeset
29 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1315
diff changeset
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
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5744
diff changeset
33 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1633
diff changeset
34 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1633
diff changeset
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
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
39 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
40 #include "error.h"
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
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
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2200
diff changeset
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
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
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
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
51 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
52 #include "utils.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2200
diff changeset
53 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
55 // TRUE means that Octave will try to beep obnoxiously before printing
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
56 // error messages.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
57 static bool Vbeep_on_error = false;
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
58
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
59 // TRUE means that Octave will try to enter the debugger when an error
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
60 // is encountered. This will also inhibit printing of the normal
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
61 // traceback message (you will only see the top-level error message).
7353
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
62 bool Vdebug_on_error = false;
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
63
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
64 // TRUE means that Octave will try to enter the debugger when an error
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
65 // is encountered within the 'try' section of a 'try' / 'catch' block.
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
66 bool Vdebug_on_caught = false;
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
67
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
68 // TRUE means that Octave will try to enter the debugger when a warning
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
69 // is encountered.
7353
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
70 bool Vdebug_on_warning = false;
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
71
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
72 // TRUE means that Octave will try to display a stack trace when a
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
73 // warning is encountered.
18128
d96747f74b1e enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
74 static bool Vbacktrace_on_warning = true;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
75
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
76 // TRUE means that Octave will print a verbose warning. Currently unused.
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
77 static bool Vverbose_warning;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
78
18742
bd334b6af257 Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents: 18222
diff changeset
79 // TRUE means that Octave will print no warnings, but lastwarn will be updated
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
80 static bool Vquiet_warning = false;
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
81
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
82 // A structure containing (most of) the current state of warnings.
11058
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
83 static octave_map warning_options;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
84
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
85 // The text of the last error message.
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
86 static std::string Vlast_error_message;
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
87
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
88 // The text of the last warning message.
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
89 static std::string Vlast_warning_message;
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
90
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
91 // The last warning message id.
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
92 static std::string Vlast_warning_id;
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
93
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
94 // The last error message id.
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
95 static std::string Vlast_error_id;
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
96
21004
f7e416862e90 doc: fix spelling of "occurred".
Rafael Laboissiere <rafael@laboissiere.net>
parents: 20963
diff changeset
97 // The last file in which an error occurred
10767
2b041d3995a3 modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10605
diff changeset
98 static octave_map Vlast_error_stack;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
99
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 103
diff changeset
100 // Current error state.
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
101 //
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
102 // Valid values:
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
103 //
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
104 // 0: no error
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
105 // 1: an error has occurred
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
106 //
672
066e1551639c [project @ 1994-09-07 21:10:32 by jwe]
jwe
parents: 610
diff changeset
107 int error_state = 0;
066e1551639c [project @ 1994-09-07 21:10:32 by jwe]
jwe
parents: 610
diff changeset
108
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
109 // Tell the error handler whether to print messages, or just store
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
110 // them for later. Used for handling errors in eval() and
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
111 // the 'unwind_protect' statement.
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4452
diff changeset
112 int buffer_error_messages = 0;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
113
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
114 // The number of layers of try / catch blocks we're in. Used to print
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
115 // "caught error" instead of error when "dbstop if caught error" is on.
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
116 int in_try_catch = 0;
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
117
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
118 // TRUE means error messages are turned off.
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
119 bool discard_error_messages = false;
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
120
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4324
diff changeset
121 // TRUE means warning messages are turned off.
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4324
diff changeset
122 bool discard_warning_messages = false;
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4324
diff changeset
123
4318
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4233
diff changeset
124 void
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4233
diff changeset
125 reset_error_handler (void)
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4233
diff changeset
126 {
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4452
diff changeset
127 buffer_error_messages = 0;
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
128 in_try_catch = 0;
4318
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4233
diff changeset
129 discard_error_messages = false;
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4233
diff changeset
130 }
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4233
diff changeset
131
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
132 static void
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
133 initialize_warning_options (const std::string& state)
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
134 {
11058
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
135 octave_scalar_map initw;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
136
11058
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
137 initw.setfield ("identifier", "all");
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
138 initw.setfield ("state", state);
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
139
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
140 warning_options = initw;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
141 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
142
10767
2b041d3995a3 modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10605
diff changeset
143 static octave_map
9166
69088b7b139c use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents: 9153
diff changeset
144 initialize_last_error_stack (void)
69088b7b139c use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents: 9153
diff changeset
145 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
146 octave::call_stack& cs
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
147 = octave::__get_call_stack__ ("initialize_last_error_stack");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
148
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
149 return cs.empty_backtrace ();
9166
69088b7b139c use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents: 9153
diff changeset
150 }
69088b7b139c use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents: 9153
diff changeset
151
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
152 static void
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
153 verror (bool save_last_error, std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
154 const char *name, const char *id, const char *fmt, va_list args,
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
155 bool with_cfn = false)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
156 {
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
157 if (discard_error_messages && ! Vdebug_on_caught)
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
158 return;
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
159
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
160 if (! buffer_error_messages || Vdebug_on_caught)
23060
baf03cdb28b5 move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
161 octave::flush_stdout ();
914
6a10b90623ea [project @ 1994-11-10 21:53:10 by jwe]
jwe
parents: 905
diff changeset
162
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
163 // FIXME: we really want to capture the message before it has all the
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
164 // formatting goop attached to it. We probably also want just the
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
165 // message, not the traceback information.
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
166
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
167 std::ostringstream output_buf;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
168
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
169 octave_vformat (output_buf, fmt, args);
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
170
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
171 std::string base_msg = output_buf.str ();
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
172
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
173 bool to_beep_or_not_to_beep_p = Vbeep_on_error;
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
174
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
175 std::string msg_string;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
176
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
177 if (to_beep_or_not_to_beep_p)
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
178 msg_string = "\a";
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
179
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
180 if (name)
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
181 {
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
182 if (in_try_catch && ! strcmp (name, "error"))
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
183 msg_string += "caught error: ";
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
184 else
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
185 msg_string += std::string (name) + ": ";
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
186 }
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
187
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
188 octave::call_stack& cs = octave::__get_call_stack__ ("verror");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
189
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
190 // If with_fcn is specified, we'll attempt to prefix the message with the name
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
191 // of the current executing function. But we'll do so only if:
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
192 // 1. the name is not empty (anonymous function)
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
193 // 2. it is not already there (including the following colon)
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
194 if (with_cfn)
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
195 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
196 octave_function *curfcn = cs.current ();
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
197 if (curfcn)
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
198 {
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
199 std::string cfn = curfcn->name ();
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
200 if (! cfn.empty ())
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
201 {
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
202 cfn += ':';
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
203 if (cfn.length () > base_msg.length ()
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
204 || base_msg.compare (0, cfn.length (), cfn) != 0)
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
205 {
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
206 msg_string += cfn + ' ';
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
207 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
208 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
209 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
210 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
211
23829
01899bdd2a3a Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents: 23812
diff changeset
212 msg_string += base_msg + '\n';
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
213
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
214 if (save_last_error)
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
215 {
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
216 // This is the first error in a possible series.
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
217
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
218 Vlast_error_id = id;
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
219 Vlast_error_message = base_msg;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
220
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
221 octave_user_code *fcn = cs.caller_user_code ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
222
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
223 if (fcn)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
224 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
225 octave_idx_type curr_frame = -1;
9166
69088b7b139c use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents: 9153
diff changeset
226
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
227 Vlast_error_stack = cs.backtrace (0, curr_frame);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
228 }
9166
69088b7b139c use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents: 9153
diff changeset
229 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
230 Vlast_error_stack = initialize_last_error_stack ();
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
231 }
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
232
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
233 if (! buffer_error_messages || Vdebug_on_caught)
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
234 {
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
235 octave_diary << msg_string;
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
236 os << msg_string;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
237 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
238 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
239
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
240 static void
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
241 pr_where_2 (std::ostream& os, const char *fmt, va_list args)
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
242 {
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
243 if (fmt)
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
244 {
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
245 if (*fmt)
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
246 {
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
247 size_t len = strlen (fmt);
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
248
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
249 if (len > 0)
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
250 {
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
251 if (fmt[len - 1] == '\n')
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
252 {
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
253 if (len > 1)
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
254 {
20827
b3f985199f3f eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents: 20826
diff changeset
255 std::string tmp_fmt (fmt, len - 1);
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
256 verror (false, os, nullptr, "", tmp_fmt.c_str (), args);
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
257 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
258 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
259 else
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
260 verror (false, os, nullptr, "", fmt, args);
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
261 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
262 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
263 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
264 else
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
265 panic ("pr_where_2: invalid format");
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
266 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
267
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
268 static void
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
269 pr_where_1 (std::ostream& os, const char *fmt, ...)
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
270 {
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
271 va_list args;
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
272 va_start (args, fmt);
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
273 pr_where_2 (os, fmt, args);
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
274 va_end (args);
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
275 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
276
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
277 struct
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
278 error_stack_frame
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
279 {
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
280 std::string name;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
281 int line;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
282 int column;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
283 };
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
284
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
285 static void
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
286 pr_where (std::ostream& os, const char *who,
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
287 const std::list<error_stack_frame>& frames)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
288 {
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
289 size_t nframes = frames.size ();
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
290
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
291 if (nframes > 0)
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
292 pr_where_1 (os, "%s: called from\n", who);
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
293
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
294 for (const auto& frm : frames)
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
295 {
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
296 std::string fcn_name = frm.name;
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
297 int line = frm.line;
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
298 int column = frm.column;
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
299
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
300 if (line > 0)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
301 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
302 if (column > 0)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
303 pr_where_1 (os, " %s at line %d column %d\n",
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
304 fcn_name.c_str (), line, column);
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
305 else
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
306 pr_where_1 (os, " %s at line %d\n", fcn_name.c_str (), line);
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
307 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
308 else
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
309 pr_where_1 (os, " %s\n", fcn_name.c_str ());
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
310 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
311 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
312
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
313 static void
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
314 pr_where (std::ostream& os, const char *who)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
315 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
316 octave::call_stack& cs = octave::__get_call_stack__ ("pr_where");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
317
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
318 std::list<octave::call_stack::stack_frame> call_stack_frames
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
319 = cs.backtrace_frames ();
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
320
20511
9502e0142c19 Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents: 20181
diff changeset
321 // Print the error message only if it is different from the previous one;
9502e0142c19 Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents: 20181
diff changeset
322 // Makes the output more concise and readable.
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
323 call_stack_frames.unique ();
20511
9502e0142c19 Simplify error output if max_recursion_depth is exceeded (Bug #45843).
Stefan Miereis <stefan.miereis@gmx.de>
parents: 20181
diff changeset
324
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
325 std::list<error_stack_frame> frames;
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
326 for (const auto& frm : call_stack_frames)
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
327 {
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
328 error_stack_frame frame;
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
329
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
330 frame.name = frm.fcn_name ();
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
331 frame.line = frm.line ();
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22809
diff changeset
332 frame.column = frm.column ();
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
333
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
334 frames.push_back (frame);
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
335 }
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
336
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
337 pr_where (os, who, frames);
19421
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
338 }
8b785ca93de7 don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents: 19415
diff changeset
339
23464
7eb0077e86f0 show stack trace for wrong type arg errors (bug #50894)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
340 octave::execution_exception
20780
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
341 make_execution_exception (const char *who)
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
342 {
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
343 std::ostringstream buf;
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
344
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
345 pr_where (buf, who);
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
346
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
347 octave::execution_exception retval;
20780
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
348
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
349 retval.set_stack_trace (buf.str ());
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
350
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
351 return retval;
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
352 }
92958b1ee100 restore stack traces to error messages
John W. Eaton <jwe@octave.org>
parents: 20777
diff changeset
353
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
354 static void
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
355 maybe_enter_debugger (octave::execution_exception& e,
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
356 bool show_stack_trace = false)
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
357 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
358 octave::call_stack& cs = octave::__get_call_stack__ ("maybe_enter_debugger");
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
359 octave::bp_table& bptab = octave::__get_bp_table__ ("maybe_enter_debugger");
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
360
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 21990
diff changeset
361 if ((octave::application::interactive ()
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 21990
diff changeset
362 || octave::application::forced_interactive ())
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
363 && ((Vdebug_on_error && bptab.debug_on_err (last_error_id ()))
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
364 || (Vdebug_on_caught && bptab.debug_on_caught (last_error_id ())))
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
365 && cs.caller_user_code ())
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
366 {
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
367 octave::unwind_protect frame;
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
368 frame.protect_var (Vdebug_on_error);
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
369 Vdebug_on_error = false;
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
370
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22121
diff changeset
371 octave::tree_evaluator::debug_mode = true;
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
372
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
373 octave::tree_evaluator::current_frame = cs.current_frame ();
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
374
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
375 if (show_stack_trace)
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
376 {
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
377 std::string stack_trace = e.info ();
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
378
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
379 if (! stack_trace.empty ())
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
380 {
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
381 std::cerr << stack_trace;
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
382
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
383 e.set_stack_trace ();
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
384 }
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
385 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
386
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
387 do_keyboard (octave_value_list ());
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
388 }
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
389 }
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
390
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
391 // Warning messages are never buffered.
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
392
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
393 static void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
394 vwarning (const char *name, const char *id, const char *fmt, va_list args)
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
395 {
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4324
diff changeset
396 if (discard_warning_messages)
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4324
diff changeset
397 return;
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4324
diff changeset
398
23060
baf03cdb28b5 move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
399 octave::flush_stdout ();
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
400
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5744
diff changeset
401 std::ostringstream output_buf;
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
402
3761
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
403 octave_vformat (output_buf, fmt, args);
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
404
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
405 // FIXME: we really want to capture the message before it has all the
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
406 // formatting goop attached to it. We probably also want just the
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
407 // message, not the traceback information.
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
408
20140
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
409 std::string base_msg = output_buf.str ();
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
410 std::string msg_string;
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
411
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
412 if (name)
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
413 msg_string = std::string (name) + ": ";
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20172
diff changeset
414
23829
01899bdd2a3a Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents: 23812
diff changeset
415 msg_string += base_msg + '\n';
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
416
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19439
diff changeset
417 Vlast_warning_id = id;
20140
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
418 Vlast_warning_message = base_msg;
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
419
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
420 if (! Vquiet_warning)
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
421 {
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
422 octave_diary << msg_string;
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
423
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
424 std::cerr << msg_string;
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
425 }
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
426 }
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
427
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
428 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
429 vmessage (const char *name, const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
430 {
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
431 verror (false, std::cerr, name, "", fmt, args);
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
432 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
433
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
434 void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
435 message (const char *name, const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
436 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
437 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
438 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
439 vmessage (name, fmt, args);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
440 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
441 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
442
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
443 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
444 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
445 va_list args)
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
446 {
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
447 verror (false, std::cerr, name, id, fmt, args);
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
448 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
449
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
450 void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
451 message_with_id (const char *name, const char *id, const char *fmt, ...)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
452 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
453 va_list args;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
454 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
455 vmessage_with_id (name, id, fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
456 va_end (args);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
457 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
458
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
459 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
460 void
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
461 usage_1 (octave::execution_exception& e, const char *id,
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
462 const char *fmt, va_list args)
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
463 {
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
464 verror (true, std::cerr, "usage", id, fmt, args);
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
465
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
466 maybe_enter_debugger (e);
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
467
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
468 throw e;
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
469 }
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
470
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
471 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
472 void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
473 usage_1 (const char *id, const char *fmt, va_list args)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
474 {
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
475 octave::execution_exception e = make_execution_exception ("usage");
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
476
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
477 usage_1 (e, id, fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
478 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
479
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
480 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
481 vusage (const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
482 {
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
483 usage_1 ("", fmt, args);
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
484 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
485
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
486 void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
487 usage (const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
488 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
489 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
490 va_start (args, fmt);
21015
b009c65ec062 Stop deprecated warning about use of vusage in usage().
Rik <rik@octave.org>
parents: 21005
diff changeset
491 usage_1 ("", fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
492 va_end (args);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
493 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
494
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
495 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
496 vusage_with_id (const char *id, const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
497 {
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
498 usage_1 (id, fmt, args);
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
499 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
500
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
501 void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
502 usage_with_id (const char *id, const char *fmt, ...)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
503 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
504 va_list args;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
505 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
506 vusage_with_id (id, fmt, args);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
507 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
508 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
509
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
510 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
511 void
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
512 error_1 (octave::execution_exception& e, std::ostream& os,
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
513 const char *name, const char *id, const char *fmt,
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
514 va_list args, bool with_cfn = false)
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
515 {
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
516 bool show_stack_trace = false;
20127
a42de4173533 also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents: 20101
diff changeset
517
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
518 if (fmt)
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
519 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
520 if (*fmt)
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
521 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
522 size_t len = strlen (fmt);
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
523
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
524 if (len > 0)
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
525 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
526 if (fmt[len - 1] == '\n')
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
527 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
528 if (len > 1)
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
529 {
20827
b3f985199f3f eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents: 20826
diff changeset
530 std::string tmp_fmt (fmt, len - 1);
b3f985199f3f eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents: 20826
diff changeset
531 verror (true, os, name, id, tmp_fmt.c_str (),
b3f985199f3f eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents: 20826
diff changeset
532 args, with_cfn);
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
533 }
20822
40fc94a24a97 if error format ends with newline, suppress stack trace (bug #46608)
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
534
40fc94a24a97 if error format ends with newline, suppress stack trace (bug #46608)
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
535 // If format ends with newline, suppress stack trace.
40fc94a24a97 if error format ends with newline, suppress stack trace (bug #46608)
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
536 e.set_stack_trace ();
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
537 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
538 else
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
539 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
540 verror (true, os, name, id, fmt, args, with_cfn);
18742
bd334b6af257 Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents: 18222
diff changeset
541
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
542 octave::call_stack& cs
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
543 = octave::__get_call_stack__ ("error_1");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
544
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
545 bool in_user_code = cs.caller_user_code () != nullptr;
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
546
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
547 if (in_user_code && ! discard_error_messages)
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
548 show_stack_trace = true;
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
549 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
550 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
551 }
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
552 }
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
553 else
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
554 panic ("error_1: invalid format");
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
555
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
556 maybe_enter_debugger (e, show_stack_trace);
18742
bd334b6af257 Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents: 18222
diff changeset
557
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
558 throw e;
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
559 }
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
560
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
561 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
562 void
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
563 error_1 (std::ostream& os, const char *name, const char *id,
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
564 const char *fmt, va_list args, bool with_cfn = false)
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
565 {
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
566 octave::execution_exception e = make_execution_exception ("error");
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
567
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20780
diff changeset
568 error_1 (e, os, name, id, fmt, args, with_cfn);
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
569 }
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
570
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
571 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
572 verror (const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
573 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
574 error_1 (std::cerr, "error", "", fmt, args);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
575 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
576
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
577 void
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
578 error (const char *fmt, ...)
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
579 {
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
580 va_list args;
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
581 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
582 verror (fmt, args);
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
583 va_end (args);
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
584 }
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
585
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
586 void
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
587 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
588 {
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
589 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
590 }
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
591
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
592 void
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
593 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
594 {
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
595 va_list args;
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
596 va_start (args, fmt);
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
597 verror (e, fmt, args);
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
598 va_end (args);
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
599 }
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
600
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
601 void
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
602 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
603 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
604 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
605 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
606
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
607 void
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
608 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
609 {
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
610 va_list args;
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
611 va_start (args, fmt);
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
612 verror_with_cfn (fmt, args);
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
613 va_end (args);
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
614 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
615
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
616 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
617 verror_with_id (const char *id, const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
618 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
619 error_1 (std::cerr, "error", id, fmt, args);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
620 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
621
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
622 void
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
623 error_with_id (const char *id, const char *fmt, ...)
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
624 {
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
625 va_list args;
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
626 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
627 verror_with_id (id, fmt, args);
6000
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
628 va_end (args);
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
629 }
fbe7ccb47f62 [project @ 2006-09-26 15:43:44 by jwe]
jwe
parents: 5998
diff changeset
630
9753
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
631 void
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
632 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
633 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
634 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
635 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
636
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
637 void
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
638 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
639 {
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
640 va_list args;
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
641 va_start (args, fmt);
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
642 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
643 va_end (args);
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
644 }
892e2aa7bc75 improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents: 9675
diff changeset
645
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
646 static int
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
647 check_state (const std::string& state)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
648 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
649 // -1: not found
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
650 // 0: found, "off"
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
651 // 1: found, "on"
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
652 // 2: found, "error"
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
653
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
654 if (state == "off")
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
655 return 0;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
656 else if (state == "on")
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
657 return 1;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
658 else if (state == "error")
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
659 return 2;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
660 else
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
661 return -1;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
662 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
663
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
664 // For given warning ID, return 0 if warnings are disabled, 1 if
14042
57e19c30b7d6 assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents: 13987
diff changeset
665 // enabled, and 2 if the given ID should be an error instead of a
57e19c30b7d6 assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents: 13987
diff changeset
666 // warning.
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
667
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
668 int
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
669 warning_enabled (const std::string& id)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
670 {
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
671 int retval = 0;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
672
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
673 int all_state = -1;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
674 int id_state = -1;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
675
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
676 octave_idx_type nel = warning_options.numel ();
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
677
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
678 if (nel > 0)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
679 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
680 Cell identifier = warning_options.contents ("identifier");
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
681 Cell state = warning_options.contents ("state");
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
682
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
683 bool all_found = false;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
684 bool id_found = false;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
685
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
686 for (octave_idx_type i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
687 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
688 octave_value ov = identifier(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
689 std::string ovs = ov.string_value ();
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
690
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
691 if (! all_found && ovs == "all")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
692 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
693 all_state = check_state (state(i).string_value ());
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
694
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
695 if (all_state >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
696 all_found = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
697 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
698
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
699 if (! id_found && ovs == id)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
700 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
701 id_state = check_state (state(i).string_value ());
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
702
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
703 if (id_state >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
704 id_found = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
705 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
706
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
707 if (all_found && id_found)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
708 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
709 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
710 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
711
14042
57e19c30b7d6 assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents: 13987
diff changeset
712 // If "all" is not present, assume warnings are enabled.
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
713 if (all_state == -1)
14042
57e19c30b7d6 assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents: 13987
diff changeset
714 all_state = 1;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
715
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
716 if (all_state == 0)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
717 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
718 if (id_state >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
719 retval = id_state;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
720 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
721 else if (all_state == 1)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
722 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
723 if (id_state == 0 || id_state == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
724 retval = id_state;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
725 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
726 retval = all_state;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
727 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
728 else if (all_state == 2)
7206
6e4ceeeb1940 [project @ 2007-11-27 22:40:20 by jwe]
jwe
parents: 7202
diff changeset
729 {
6e4ceeeb1940 [project @ 2007-11-27 22:40:20 by jwe]
jwe
parents: 7202
diff changeset
730 if (id_state == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
731 retval= id_state;
7206
6e4ceeeb1940 [project @ 2007-11-27 22:40:20 by jwe]
jwe
parents: 7202
diff changeset
732 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
733 retval = all_state;
7206
6e4ceeeb1940 [project @ 2007-11-27 22:40:20 by jwe]
jwe
parents: 7202
diff changeset
734 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
735
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
736 return retval;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
737 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
738
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
739 static void
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
740 warning_1 (const char *id, const char *fmt, va_list args)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
741 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
742 int warn_opt = warning_enabled (id);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
743
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
744 if (warn_opt == 2)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
745 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
746 // Handle this warning as an error.
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
747
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
748 error_1 (std::cerr, "error", id, fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
749 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
750 else if (warn_opt == 1)
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
751 {
20140
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
752 bool fmt_suppresses_backtrace = false;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23448
diff changeset
753 size_t fmt_len = (fmt ? strlen (fmt) : 0);
20140
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
754 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n');
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
755
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
756 if (fmt_suppresses_backtrace && fmt_len > 1)
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
757 {
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
758 // Strip newline before issuing warning
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
759 std::string tmp_fmt (fmt, fmt_len - 1);
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
760 vwarning ("warning", id, tmp_fmt.c_str (), args);
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
761 }
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
762 else
64a2d4c87ecb Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents: 20130
diff changeset
763 vwarning ("warning", id, fmt, args);
8973
ddea8b06ed7c fix warning backtrace
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
764
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
765 octave::call_stack& cs = octave::__get_call_stack__ ("warning_1");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
766
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
767 bool in_user_code = cs.caller_user_code () != nullptr;
20127
a42de4173533 also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents: 20101
diff changeset
768
20130
0aed244dbdb3 don't print stack trace if warning format ends with newline character
John W. Eaton <jwe@octave.org>
parents: 20127
diff changeset
769 if (! fmt_suppresses_backtrace && in_user_code
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
770 && Vbacktrace_on_warning
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
771 && ! discard_warning_messages)
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
772 pr_where (std::cerr, "warning");
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
773
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
774 octave::bp_table& bptab
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
775 = octave::__get_bp_table__ ("warning_1");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
776
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 21990
diff changeset
777 if ((octave::application::interactive ()
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 21990
diff changeset
778 || octave::application::forced_interactive ())
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
779 && Vdebug_on_warning && in_user_code && bptab.debug_on_warn (id))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
780 {
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
781 octave::unwind_protect frame;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
782 frame.protect_var (Vdebug_on_warning);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
783 Vdebug_on_warning = false;
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
784
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22121
diff changeset
785 octave::tree_evaluator::debug_mode = true;
18742
bd334b6af257 Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents: 18222
diff changeset
786
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
787 octave::tree_evaluator::current_frame = cs.current_frame ();
18742
bd334b6af257 Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents: 18222
diff changeset
788
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
789 do_keyboard (octave_value_list ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
790 }
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
791 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
792 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
793
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
794 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
795 vwarning (const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
796 {
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
797 warning_1 ("", fmt, args);
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
798 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
799
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
800 void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
801 warning (const char *fmt, ...)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
802 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
803 va_list args;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
804 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
805 vwarning (fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
806 va_end (args);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
807 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
808
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
809 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
810 vwarning_with_id (const char *id, const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
811 {
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
812 warning_1 (id, fmt, args);
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
813 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
814
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
815 void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
816 warning_with_id (const char *id, const char *fmt, ...)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
817 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
818 va_list args;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
819 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
820 vwarning_with_id (id, fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
821 va_end (args);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
822 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
823
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
824 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
825 vparse_error (const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
826 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
827 error_1 (std::cerr, nullptr, "", fmt, args);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
828 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
829
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
830 void
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
831 parse_error (const char *fmt, ...)
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
832 {
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
833 va_list args;
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
834 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
835 vparse_error (fmt, args);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
836 va_end (args);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
837 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
838
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
839 void
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
840 vparse_error_with_id (const char *id, const char *fmt, va_list args)
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
841 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
842 error_1 (std::cerr, nullptr, id, fmt, args);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
843 }
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
844
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
845 void
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
846 parse_error_with_id (const char *id, const char *fmt, ...)
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
847 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
848 va_list args;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
849 va_start (args, fmt);
6338
ec88b4ab6d10 [project @ 2007-02-22 07:07:19 by jwe]
jwe
parents: 6000
diff changeset
850 vparse_error_with_id (id, fmt, args);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
851 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
852 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
853
189
de0e58f9b064 [project @ 1993-10-28 08:52:15 by jwe]
jwe
parents: 169
diff changeset
854 void
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
855 rethrow_error (const char *id, const char *fmt, ...)
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
856 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
857 va_list args;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
858 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
859 error_1 (std::cerr, nullptr, id, fmt, args);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
860 va_end (args);
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
861 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
862
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
863 static std::list<error_stack_frame>
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
864 make_stack_frame_list (const octave_map& stack)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
865 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
866 std::list<error_stack_frame> frames;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
867
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
868 Cell name = stack.contents ("name");
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
869 Cell line = stack.contents ("line");
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
870 Cell column;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
871 bool have_column = false;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
872 if (stack.contains ("column"))
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
873 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
874 have_column = true;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
875 column = stack.contents ("column");
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
876 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
877
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
878 octave_idx_type nel = name.numel ();
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
879
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
880 for (octave_idx_type i = 0; i < nel; i++)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
881 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
882 error_stack_frame frame;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
883
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
884 frame.name = name(i).string_value ();
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
885 frame.line = line(i).int_value ();
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23448
diff changeset
886 frame.column = (have_column ? column(i).int_value () : -1);
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
887
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
888 frames.push_back (frame);
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
889 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
890
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
891 return frames;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
892 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
893
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
894 static void
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
895 rethrow_error_1 (const char *id, const char *fmt, ...)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
896 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
897 va_list args;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
898 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
899 verror (false, std::cerr, nullptr, id, fmt, args);
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
900 va_end (args);
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
901 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
902
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
903 OCTAVE_NORETURN static
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
904 void
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
905 rethrow_error (const std::string& id, const std::string& msg,
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
906 const octave_map& stack)
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
907 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
908 octave::execution_exception e = make_execution_exception ("error");
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
909
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
910 if (! stack.isempty ()
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
911 && ! (stack.contains ("file") && stack.contains ("name")
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
912 && stack.contains ("line")))
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
913 error ("rethrow: STACK struct must contain the fields 'file', 'name', and 'line'");
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
914
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
915 Vlast_error_id = id;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
916 Vlast_error_message = msg;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
917 Vlast_error_stack = stack;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
918
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
919 size_t len = msg.length ();
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
920
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
921 std::string tmp_msg (msg);
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
922 if (len > 1 && tmp_msg[len-1] == '\n')
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
923 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
924 tmp_msg.erase (len - 1);
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
925
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
926 rethrow_error_1 (id.c_str (), "%s\n", tmp_msg.c_str ());
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
927 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
928 else
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
929 rethrow_error_1 (id.c_str (), "%s", tmp_msg.c_str ());
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
930
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
931 if (! stack.isempty ())
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
932 {
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
933 std::ostringstream buf;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
934
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
935 pr_where (buf, "error", make_stack_frame_list (stack));
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
936
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
937 e.set_stack_trace (buf.str ());
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
938 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
939
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
940 throw e;
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
941 }
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
942
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
943 void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
944 panic (const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
945 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
946 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
947 va_start (args, fmt);
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4452
diff changeset
948 buffer_error_messages = 0;
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
949 discard_error_messages = false;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
950 verror (false, std::cerr, "panic", "", fmt, args);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
951 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
952 abort ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
953 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
954
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
955 static void
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
956 defun_usage_message_1 (const char *fmt, ...)
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
957 {
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
958 va_list args;
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
959 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
960 error_1 (octave_stdout, nullptr, "", fmt, args);
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
961 va_end (args);
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
962 }
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
963
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
964 void
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
965 defun_usage_message (const std::string& msg)
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
966 {
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
967 defun_usage_message_1 ("%s", msg.c_str ());
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
968 }
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4731
diff changeset
969
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
970 typedef void (*error_fun)(const char *, const char *, ...);
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
971
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
972 extern octave_value_list Fsprintf (const octave_value_list&, int);
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
973
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
974 static std::string
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
975 handle_message (error_fun f, const char *id, const char *msg,
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
976 const octave_value_list& args, bool have_fmt)
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
977 {
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
978 std::string retval;
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
979
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
980 std::string tstr;
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1633
diff changeset
981
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
982 if (args.length () > 0)
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
983 {
3066
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
984 octave_value arg;
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
985
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
986 if (have_fmt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
987 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
988 octave_value_list tmp = Fsprintf (args, 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
989 arg = tmp(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
990 }
3066
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
991 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
992 arg = args(0);
2745
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
993
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
994 if (arg.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
995 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
996 if (arg.is_string ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
997 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
998 tstr = arg.string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
999 msg = tstr.c_str ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1000
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1001 if (! msg)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1002 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1003 }
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
1004 else if (arg.isempty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1005 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1006 }
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
1007 }
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
1008
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
1009 // Ugh.
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
1010
9675
ef45d191d833 error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents: 9588
diff changeset
1011 size_t len = strlen (msg);
ef45d191d833 error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents: 9588
diff changeset
1012
ef45d191d833 error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents: 9588
diff changeset
1013 if (len > 0)
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
1014 {
9675
ef45d191d833 error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents: 9588
diff changeset
1015 if (msg[len - 1] == '\n')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1016 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1017 if (len > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1018 {
20827
b3f985199f3f eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents: 20826
diff changeset
1019 std::string tmp_msg (msg, len - 1);
b3f985199f3f eliminate memory leaks in error functions
John W. Eaton <jwe@octave.org>
parents: 20826
diff changeset
1020 f (id, "%s\n", tmp_msg.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1021 retval = tmp_msg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1022 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1023 }
9675
ef45d191d833 error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents: 9588
diff changeset
1024 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1025 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1026 f (id, "%s", msg);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1027 retval = msg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1028 }
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1029 }
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
1030
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
1031 return retval;
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
1032 }
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
1033
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1034 DEFUN (rethrow, 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
1035 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
1036 @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
1037 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
1038
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1039 @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
1040 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
1041 @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
1042 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
1043 @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
1044 @end deftypefn */)
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1045 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
1046 if (args.length () != 1)
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6671
diff changeset
1047 print_usage ();
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1048
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1049 const octave_scalar_map err = args(0).scalar_map_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1050
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
1051 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
1052 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
1053
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1054 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
1055 std::string id = err.contents ("identifier").string_value ();
6483
d00da2148c53 [project @ 2007-04-04 02:58:48 by jwe]
jwe
parents: 6427
diff changeset
1056
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1057 octave_map err_stack = initialize_last_error_stack ();
6483
d00da2148c53 [project @ 2007-04-04 02:58:48 by jwe]
jwe
parents: 6427
diff changeset
1058
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1059 if (err.contains ("stack"))
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
1060 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
1061
22808
1d3d0321bc5d preserve lasterror info on rethrow (bug #49642)
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
1062 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
1063
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21040
diff changeset
1064 return ovl ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1065 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1066
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1067 // Determine whether the first argument to error or warning function
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1068 // should be handled as the message identifier or as the format string.
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1069
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1070 static bool
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1071 maybe_extract_message_id (const std::string& caller,
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1072 const octave_value_list& args,
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1073 octave_value_list& nargs,
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1074 std::string& id)
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1075 {
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1076 nargs = args;
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 21015
diff changeset
1077 id = "";
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1078
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1079 int nargin = args.length ();
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1080
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1081 bool have_fmt = nargin > 1;
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1082
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1083 if (nargin > 0)
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1084 {
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1085 std::string arg1 = args(0).string_value ();
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1086
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23795
diff changeset
1087 // For compatibility with Matlab, an identifier must contain ':',
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23795
diff changeset
1088 // but not at the beginning or the end, and it must not contain '%'
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23795
diff changeset
1089 // (even if it is not a valid conversion operator) or whitespace.
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1090
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1091 if (arg1.find_first_of ("% \f\n\r\t\v") == std::string::npos
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1092 && arg1.find (':') != std::string::npos
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1093 && arg1[0] != ':'
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23795
diff changeset
1094 && arg1.back () != ':')
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1095 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1096 if (nargin > 1)
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1097 {
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1098 id = arg1;
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1099
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1100 nargs.resize (nargin-1);
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1101
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1102 for (int i = 1; i < nargin; i++)
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1103 nargs(i-1) = args(i);
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1104 }
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1105 else
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1106 nargs(0) = "call to " + caller
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1107 + " with message identifier '" + arg1
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1108 + "' requires message";
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1109 }
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1110 }
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1111
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1112 return have_fmt;
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1113 }
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1114
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
1115 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
1116 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
1117 @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
1118 @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
1119 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
1120
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1121 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
1122 @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
1123 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
1124 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
1125 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
1126
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1127 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
1128 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
1129 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
1130
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1131 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
1132 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
1133 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
1134
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1135 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1136 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1137 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
1138 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
1139 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
1140 @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
1141 @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
1142
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1143 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1144 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
1145 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
1146
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1147 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1148 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1149 f ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1150 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
1151 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
1152 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
1153 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
1154 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
1155 @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
1156 @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
1157
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1158 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
1159 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
1160 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
1161 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
1162 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
1163
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1164 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1165 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1166 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
1167 f ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1168 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
1169 @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
1170 @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
1171
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1172 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
1173 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
1174 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
1175 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
1176
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1177 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1178 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1179 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
1180 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
1181 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
1182 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
1183 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
1184 @dots{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1185 endif
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1186 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
1187 @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
1188 @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
1189
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1190 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1191 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
1192
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1193 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
1194 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
1195 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
1196 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
1197 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
1198 (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
1199 @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
1200 @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
1201 @end deftypefn */)
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
1202 {
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1203
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1204 int nargin = args.length ();
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1205
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1206 if (nargin == 0)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1207 print_usage ();
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1208
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1209 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20897
diff changeset
1210
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1211 octave_value_list nargs = args;
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1212
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1213 std::string id;
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1214
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1215 bool have_fmt = false;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1216
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
1217 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
1218 {
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1219 // 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
1220 if (args(0).isempty ())
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1221 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
1222
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1223 octave_scalar_map m = args(0).scalar_map_value ();
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1224
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1225 // 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
1226 if (m.nfields () == 0)
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1227 return retval;
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1228
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1229 if (m.contains ("message"))
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1230 {
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1231 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
1232
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1233 if (c.is_string ())
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1234 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
1235 }
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1236
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1237 if (m.contains ("identifier"))
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1238 {
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1239 octave_value c = m.getfield ("identifier");
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1240
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1241 if (c.is_string ())
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1242 id = c.string_value ();
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1243 }
9675
ef45d191d833 error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents: 9588
diff changeset
1244
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1245 // 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
1246 // 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
1247 // handle_message, error_with_id, etc.
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1248 }
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1249 else
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1250 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
1251
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1252 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
1253 nargs, have_fmt);
7252
d35fa45980c6 [project @ 2007-12-04 19:02:46 by jwe]
jwe
parents: 7206
diff changeset
1254
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1255 return retval;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
1256 }
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
1257
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1258 static octave_scalar_map
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1259 warning_query (const std::string& id_arg)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1260 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1261 octave_scalar_map retval;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1262
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1263 std::string id = id_arg;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1264
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1265 if (id == "last")
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1266 id = Vlast_warning_id;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1267
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1268 Cell ident = warning_options.contents ("identifier");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1269 Cell state = warning_options.contents ("state");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1270
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1271 octave_idx_type nel = ident.numel ();
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1272
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1273 assert (nel != 0);
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1274
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1275 bool found = false;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1276
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1277 std::string val;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1278
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1279 for (octave_idx_type i = 0; i < nel; i++)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1280 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1281 if (ident(i).string_value () == id)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1282 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1283 val = state(i).string_value ();
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1284 found = true;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1285 break;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1286 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1287 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1288
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1289 if (! found)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1290 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1291 for (octave_idx_type i = 0; i < nel; i++)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1292 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1293 if (ident(i).string_value () == "all")
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1294 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1295 val = state(i).string_value ();
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1296 found = true;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1297 break;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1298 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1299 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1300 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1301
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1302 // The warning state "all" is always supposed to remain in the list,
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1303 // so we should always find a state, either explicitly or by using the
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1304 // state for "all".
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1305
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1306 assert (found);
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1307
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1308 retval.assign ("identifier", id);
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20511
diff changeset
1309 retval.assign ("state", val);
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1310
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1311 return retval;
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1312 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1313
19439
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1314 static std::string
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1315 default_warning_state (void)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1316 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1317 std::string retval = "on";
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1318
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1319 Cell ident = warning_options.contents ("identifier");
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1320 Cell state = warning_options.contents ("state");
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1321
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1322 octave_idx_type nel = ident.numel ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1323
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1324 for (octave_idx_type i = 0; i < nel; i++)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1325 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1326 if (ident(i).string_value () == "all")
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1327 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1328 retval = state(i).string_value ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1329 break;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1330 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1331 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1332
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1333 return retval;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1334 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1335
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1336 static void
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1337 display_warning_options (std::ostream& os)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1338 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1339 Cell ident = warning_options.contents ("identifier");
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1340 Cell state = warning_options.contents ("state");
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1341
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1342 octave_idx_type nel = ident.numel ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1343
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1344 std::string all_state = default_warning_state ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1345
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1346 if (all_state == "on")
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1347 os << "By default, warnings are enabled.";
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1348 else if (all_state == "off")
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1349 os << "By default, warnings are disabled.";
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1350 else if (all_state == "error")
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1351 os << "By default, warnings are treated as errors.";
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1352 else
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1353 panic_impossible ();
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19444
diff changeset
1354
19439
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1355 if (nel > 1)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1356 os << "\n\n";
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1357
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1358 // The state for all is always supposed to be first in the list.
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1359
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1360 for (octave_idx_type i = 1; i < nel; i++)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1361 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1362 std::string tid = ident(i).string_value ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1363 std::string tst = state(i).string_value ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1364
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1365 os << std::setw (7) << tst << " " << tid << "\n";
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1366 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1367
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1368 os << std::endl;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1369 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1370
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1371 static void
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1372 set_warning_option (const std::string& state, const std::string& ident)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1373 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1374 std::string all_state = default_warning_state ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1375
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1376 if (state != "on" && state != "off" && state != "error")
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1377 error ("invalid warning state: %s", state.c_str ());
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1378
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1379 Cell tid = warning_options.contents ("identifier");
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1380 Cell tst = warning_options.contents ("state");
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1381
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1382 octave_idx_type nel = tid.numel ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1383
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1384 for (octave_idx_type i = 0; i < nel; i++)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1385 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1386 if (tid(i).string_value () == ident)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1387 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1388 // We found it in the current list of options. If the state
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1389 // for "all" is same as arg1, we can simply remove the item
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1390 // from the list.
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1391
22121
879f297f3194 Retain at least "all" in warning list (bug #47543)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1392 if (state == all_state && ident != "all")
19439
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1393 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1394 for (i = i + 1; i < nel; i++)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1395 {
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1396 tid(i-1) = tid(i);
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1397 tst(i-1) = tst(i);
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1398 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1399
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1400 tid.resize (dim_vector (1, nel-1));
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1401 tst.resize (dim_vector (1, nel-1));
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1402 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1403 else
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1404 tst(i) = state;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1405
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1406 warning_options.clear ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1407
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1408 warning_options.assign ("identifier", tid);
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1409 warning_options.assign ("state", tst);
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1410
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1411 return;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1412 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1413 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1414
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1415 // The option wasn't already in the list. Append it.
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1416
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1417 tid.resize (dim_vector (1, nel+1));
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1418 tst.resize (dim_vector (1, nel+1));
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1419
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1420 tid(nel) = ident;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1421 tst(nel) = state;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1422
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1423 warning_options.clear ();
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1424
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1425 warning_options.assign ("identifier", tid);
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1426 warning_options.assign ("state", tst);
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1427 }
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1428
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1429 DEFMETHOD (warning, interp, args, nargout,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1430 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
1431 @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
1432 @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
1433 @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
1434 @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
1435 @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
1436 @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
1437 @deftypefnx {} {} warning (@var{state}, @var{id}, "local")
25215
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1438 @deftypefnx {} {} warning (@var{warning_struct})
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1439 @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
1440 @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
1441
25215
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1442 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
1443
25215
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1444 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
1445 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
1446 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
1447 (@pxref{Formatted Output}) and prefixed by the character string
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1448 @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
1449 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
1450 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
1451
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1452 @example
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1453 @group
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1454 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
1455 @end group
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1456 @end example
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1457
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1458 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
1459 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
1460 form @qcode{"NAMESPACE:WARNING-NAME"}. Octave's own warnings use the
24441
9fbb5de78ec7 maint: merge stable to default.
Rik <rik@octave.org>
parents: 24361 24440
diff changeset
1461 @qcode{"Octave"} namespace (@pxref{XREFwarning_ids,,warning_ids}). For
9fbb5de78ec7 maint: merge stable to default.
Rik <rik@octave.org>
parents: 24361 24440
diff changeset
1462 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
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
24047
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1466 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
1467 "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
1468 @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
1469 @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
1470
24047
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1471 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
1472 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
1473 @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
1474 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
1475
25215
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1476 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
1477 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
1478 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
1479
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1480 @table @asis
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1481 @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
1482 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
1483 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
1484
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1485 @item @qcode{"error"}:
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1486 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
1487 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
1488
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1489 @item @qcode{"query"}:
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1490 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
1491 @end table
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1492
25215
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1493 A structure or structure array @var{warning_struct}, with fields
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1494 @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
1495 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
1496 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
1497
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1498 @example
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1499 @group
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1500 loglog (-1:10);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1501 ## 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
1502 [~, id] = lastwarn ();
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1503 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
1504 loglog (-1:10);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1505 ## 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
1506 warning (warnstate);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1507 @end group
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1508 @end example
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1509
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1510 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
1511 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
1512 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
1513 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
1514 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
1515 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
1516
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1517 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
1518 @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
1519 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
1520
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1521 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
1522 modes @var{mode}:
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1523
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1524 @table @asis
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1525 @item @qcode{"backtrace"}:
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1526 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
1527
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1528 @item @qcode{"verbose"}:
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1529 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
1530 @end table
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1531
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1532 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
1533 @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
1534
25215
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1535 Implementation Note: For compatibility with @sc{matlab}, escape sequences in
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1536 @var{template} (e.g., @qcode{"@xbackslashchar{}n"} => newline) are processed
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1537 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
1538 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
1539 expansion use a second backslash before the sequence (e.g.,
7ca5f8c70879 doc: Update docstring for warning().
Rik <rik@octave.org>
parents: 25164
diff changeset
1540 @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
1541 @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
1542 @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
1543 @end deftypefn */)
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
1544 {
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1545 octave_value retval;
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1546
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1547 int nargin = args.length ();
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1548 bool done = false;
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1549
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1550 if (nargin > 0 && args.all_strings_p ())
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1551 {
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1552 string_vector argv = args.make_argv ("warning");
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1553
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
1554 std::string arg1 = argv[1];
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1555 std::string arg2 = "all";
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1556
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1557 if (nargin >= 2)
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
1558 arg2 = argv[2];
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1559
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1560 if (arg1 == "on" || arg1 == "off" || arg1 == "error")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1561 {
24047
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1562 // Prepare output structure
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1563 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
1564 if (arg2 == "all")
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1565 old_warning_options = warning_options;
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1566 else
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1567 old_warning_options = octave_map (warning_query (arg2));
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1568
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
1569 octave::symbol_table& symtab = interp.get_symbol_table ();
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1570
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
1571 if (nargin == 3 && argv[3] == "local"
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23584
diff changeset
1572 && ! symtab.at_top_level ())
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1573 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1574 octave::symbol_scope scope
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1575 = symtab.require_current_scope ("warning");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1576
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1577 octave_scalar_map val = warning_query (arg2);
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1578
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1579 octave_value curr_state = val.contents ("state");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1580
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1581 // 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
1582
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1583 octave_value curr_warning_states
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1584 = scope.varval (".saved_warning_states.");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1585
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1586 octave_map m;
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1587
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1588 if (curr_warning_states.is_defined ())
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1589 m = curr_warning_states.map_value ();
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1590 else
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1591 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1592 string_vector fields (2);
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1593
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1594 fields(0) = "identifier";
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1595 fields(1) = "state";
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1596
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1597 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
1598 }
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1599
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1600 Cell ids = m.contents ("identifier");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1601 Cell states = m.contents ("state");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1602
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1603 octave_idx_type nel = states.numel ();
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1604 bool found = false;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1605 octave_idx_type i;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1606 for (i = 0; i < nel; i++)
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1607 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1608 std::string id = ids(i).string_value ();
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1609
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1610 if (id == arg2)
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1611 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1612 states(i) = curr_state;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1613 found = true;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1614 break;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1615 }
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1616 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1617
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1618 if (! found)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1619 {
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1620 m.resize (dim_vector (nel+1, 1));
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1621
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1622 ids.resize (dim_vector (nel+1, 1));
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1623 states.resize (dim_vector (nel+1, 1));
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1624
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1625 ids(nel) = arg2;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1626 states(nel) = curr_state;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1627 }
7202
ffdbdf53665c [project @ 2007-11-27 20:14:41 by jwe]
jwe
parents: 7031
diff changeset
1628
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1629 m.contents ("identifier") = ids;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1630 m.contents ("state") = states;
7202
ffdbdf53665c [project @ 2007-11-27 20:14:41 by jwe]
jwe
parents: 7031
diff changeset
1631
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1632 scope.force_assign (".saved_warning_states.", m);
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1633
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1634 // 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
1635 // handle the current setting.
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1636 nargin--;
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1637 }
7202
ffdbdf53665c [project @ 2007-11-27 20:14:41 by jwe]
jwe
parents: 7031
diff changeset
1638
21000
85dfb551e4cd maint: Periodic merge of stable to default.
Rik <rik@octave.org>
parents: 20996 20963
diff changeset
1639 if (nargin >= 2 && arg2 == "all")
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1640 {
21000
85dfb551e4cd maint: Periodic merge of stable to default.
Rik <rik@octave.org>
parents: 20996 20963
diff changeset
1641 // If "all" is explicitly given as ID.
7202
ffdbdf53665c [project @ 2007-11-27 20:14:41 by jwe]
jwe
parents: 7031
diff changeset
1642
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1643 octave_map tmp;
22223
cf18d6e791a1 Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22196
diff changeset
1644 int is_error = (arg1 == "error");
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1645
22223
cf18d6e791a1 Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22196
diff changeset
1646 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
1647 Cell st (1, 1 + 2*is_error);
7206
6e4ceeeb1940 [project @ 2007-11-27 22:40:20 by jwe]
jwe
parents: 7202
diff changeset
1648
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1649 id(0) = arg2;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1650 st(0) = arg1;
7206
6e4ceeeb1940 [project @ 2007-11-27 22:40:20 by jwe]
jwe
parents: 7202
diff changeset
1651
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1652 // 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
1653 // 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
1654 // 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
1655 // Octave:language-extension.
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1656
22223
cf18d6e791a1 Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22196
diff changeset
1657 if (is_error)
cf18d6e791a1 Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22196
diff changeset
1658 {
cf18d6e791a1 Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22196
diff changeset
1659 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
1660 st(1) = "off";
7202
ffdbdf53665c [project @ 2007-11-27 20:14:41 by jwe]
jwe
parents: 7031
diff changeset
1661
22223
cf18d6e791a1 Prevent Octave:language-extension from becoming an error (bug #44336).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22196
diff changeset
1662 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
1663 st(2) = "off";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1664 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1665
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1666 tmp.assign ("identifier", id);
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1667 tmp.assign ("state", st);
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents: 5567
diff changeset
1668
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1669 warning_options = tmp;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1670
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1671 done = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1672 }
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1673 else if (arg2 == "backtrace")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1674 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1675 if (arg1 != "error")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1676 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1677 Vbacktrace_on_warning = (arg1 == "on");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1678 done = true;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1679 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1680 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1681 else if (arg2 == "debug")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1682 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1683 if (arg1 != "error")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1684 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1685 Vdebug_on_warning = (arg1 == "on");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1686 done = true;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1687 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1688 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1689 else if (arg2 == "verbose")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1690 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1691 if (arg1 != "error")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1692 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1693 Vverbose_warning = (arg1 == "on");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1694 done = true;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1695 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1696 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1697 else if (arg2 == "quiet")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1698 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1699 if (arg1 != "error")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1700 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1701 Vquiet_warning = (arg1 == "on");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1702 done = true;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1703 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1704 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1705 else
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1706 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1707 if (arg2 == "last")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1708 arg2 = Vlast_warning_id;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1709
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1710 set_warning_option (arg1, arg2);
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1711
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1712 done = true;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1713 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1714
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1715 if (done && nargout > 0)
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1716 retval = old_warning_options;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1717 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1718 else if (arg1 == "query")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1719 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1720 if (arg2 == "all")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1721 retval = warning_options;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1722 else if (arg2 == "backtrace" || arg2 == "debug"
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1723 || arg2 == "verbose" || arg2 == "quiet")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1724 {
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1725 octave_scalar_map tmp;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1726 tmp.assign ("identifier", arg2);
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1727 if (arg2 == "backtrace")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1728 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1729 else if (arg2 == "debug")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1730 tmp.assign ("state", Vdebug_on_warning ? "on" : "off");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1731 else if (arg2 == "verbose")
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1732 tmp.assign ("state", Vverbose_warning ? "on" : "off");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1733 else
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1734 tmp.assign ("state", Vquiet_warning ? "on" : "off");
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1735
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1736 retval = tmp;
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1737 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1738 else
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1739 retval = warning_query (arg2);
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1740
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1741 done = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1742 }
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1743 }
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1744 else if (nargin == 0)
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1745 {
19439
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1746 if (nargout > 0)
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1747 retval = warning_options;
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1748 else
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1749 display_warning_options (octave_stdout);
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1750
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1751 done = true;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1752 }
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1753 else if (nargin == 1)
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1754 {
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1755 octave_value arg = args(0);
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1756
24047
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1757 octave_map old_warning_options;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1758
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
1759 if (arg.isstruct ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1760 {
11058
3329616444f0 replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1761 octave_map m = arg.map_value ();
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1762
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1763 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
1764 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
1765
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1766 // 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
1767
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1768 Cell ident = m.contents ("identifier");
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1769 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
1770
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1771 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
1772
24047
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1773 // Prepare output structure
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1774 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
1775 Cell oldstate (state);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1776
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1777 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
1778 {
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1779 std::string tid = ident(i).string_value ();
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1780 oldstate(i) = warning_query (tid).getfield ("state");
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1781 }
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1782 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
1783
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1784 // Set new values
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1785 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
1786 {
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1787 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
1788 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
1789
20897
9aad16a799c9 maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents: 20853
diff changeset
1790 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
1791 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1792
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1793 done = true;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1794
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1795 if (nargout > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1796 retval = old_warning_options;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1797 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1798 }
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1799
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
1800 if (! done)
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1801 {
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1802 octave_value_list nargs = args;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1803
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1804 std::string id;
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1805
14558
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1806 bool have_fmt = maybe_extract_message_id ("warning", args, nargs, id);
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1807
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1808 std::string prev_msg = Vlast_warning_message;
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1809
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
1810 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
1811 "unspecified warning", nargs,
0c9c85e702ca better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents: 14361
diff changeset
1812 have_fmt);
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1813
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1814 if (nargout > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1815 retval = prev_msg;
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1816 }
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
1817
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1818 return retval;
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1819 }
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
1820
20963
6ed7bae8017b Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20181
diff changeset
1821 /*
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1822 %!test <*45753>
20963
6ed7bae8017b Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20181
diff changeset
1823 %! warning ("error");
6ed7bae8017b Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20181
diff changeset
1824 %! assert (! isempty (help ("warning")));
6ed7bae8017b Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20181
diff changeset
1825 */
6ed7bae8017b Fix behavior of warning ("error") call (bug #45753).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20181
diff changeset
1826
24047
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1827 /*
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1828 %!test <*51997>
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1829 %! id = "Octave:divide-by-zero";
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1830 %! 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
1831 %! current_all = warning ();
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1832 %! 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
1833 %! 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
1834 %! previous = warning (current);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1835 %! assert (previous, current);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1836 %! 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
1837 %! assert (previous, current);
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1838 */
9c198d1c84cd Overhaul documentation for "warning" and fix output size (bug #51997).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23850
diff changeset
1839
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1840 octave_value_list
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1841 set_warning_state (const std::string& id, const std::string& state)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1842 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1843 octave_value_list args;
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1844
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1845 args(1) = id;
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1846 args(0) = state;
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1847
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1848 octave::interpreter& interp
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1849 = octave::__get_interpreter__ ("set_warning_state");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1850
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1851 return Fwarning (interp, args, 1);
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1852 }
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1853
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1854 octave_value_list
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1855 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
1856 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1857 octave::interpreter& interp
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1858 = octave::__get_interpreter__ ("set_warning_state");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1859
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1860 return Fwarning (interp, args, 1);
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1861 }
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1862
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1863 void
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1864 disable_warning (const std::string& id)
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10405
diff changeset
1865 {
19439
93fbdbcb3349 fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents: 19421
diff changeset
1866 set_warning_option ("off", id);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1867 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1868
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1869 void
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1870 initialize_default_warning_state (void)
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1871 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1872 initialize_warning_options ("on");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1873
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1874 // Most people will want to have the following disabled.
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1875
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21966
diff changeset
1876 disable_warning ("Octave:array-as-logical");
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1877 disable_warning ("Octave:array-to-scalar");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1878 disable_warning ("Octave:array-to-vector");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1879 disable_warning ("Octave:imag-to-real");
19852
e9a0bd0b125c Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents: 19849
diff changeset
1880 disable_warning ("Octave:language-extension");
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1881 disable_warning ("Octave:missing-semicolon");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1882 disable_warning ("Octave:neg-dim-as-zero");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1883 disable_warning ("Octave:resize-on-range-error");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1884 disable_warning ("Octave:separator-insert");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1885 disable_warning ("Octave:single-quote-string");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1886 disable_warning ("Octave:str-to-num");
13841
0a158dbdb04a Remove 3 unused warning ids
Rik <octave@nomad.inbox5.com>
parents: 13709
diff changeset
1887 disable_warning ("Octave:mixed-string-concat");
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1888 disable_warning ("Octave:variable-switch-label");
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1889 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
1890
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1891 DEFMETHOD (lasterror, interp, args, ,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
1892 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
1893 @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
1894 @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
1895 @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
1896 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
1897
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1898 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
1899 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
1900 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
1901
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1902 @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
1903 @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
1904 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
1905
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1906 @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
1907 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
1908
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1909 @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
1910 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
1911 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
1912 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
1913
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1914 @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
1915 @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
1916 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
1917
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1918 @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
1919 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
1920
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1921 @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
1922 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
1923
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1924 @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
1925 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
1926 @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
1927 @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
1928
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1929 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
1930 @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
1931 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
1932
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1933 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
1934 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
1935 @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
1936 @end deftypefn */)
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1937 {
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
1938 int nargin = args.length ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1939
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1940 if (nargin > 1)
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1941 print_usage ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1942
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1943 octave_scalar_map err;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1944
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1945 err.assign ("message", Vlast_error_message);
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1946 err.assign ("identifier", Vlast_error_id);
7976
736124a4fa3d lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents: 7882
diff changeset
1947
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1948 err.assign ("stack", octave_value (Vlast_error_stack));
7976
736124a4fa3d lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents: 7882
diff changeset
1949
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1950 if (nargin == 1)
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1951 {
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1952 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1953 {
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
1954 if (args(0).string_value () != "reset")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
1955 error ("lasterror: unrecognized string argument");
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1956
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 21015
diff changeset
1957 Vlast_error_message = "";
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 21015
diff changeset
1958 Vlast_error_id = "";
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1959
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20946
diff changeset
1960 Vlast_error_stack = initialize_last_error_stack ();
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1961 }
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
1962 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
1963 {
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1964 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
1965 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
1966 std::string new_error_message;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1967 std::string new_error_id;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1968 std::string new_error_file;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1969 std::string new_error_name;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1970 int new_error_line = -1;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1971 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
1972 bool initialize_stack = false;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1973
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1974 if (new_err.contains ("message"))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1975 {
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1976 const std::string tmp =
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1977 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
1978 new_error_message = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1979 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1980
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1981 if (new_err.contains ("identifier"))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1982 {
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1983 const std::string tmp =
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1984 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
1985 new_error_id = tmp;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1986 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
1987
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1988 if (new_err.contains ("stack"))
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1989 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
1990 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
1991 initialize_stack = true;
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
1992 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1993 {
21856
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
1994 new_err_stack =
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
1995 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
1996
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
1997 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
1998 {
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
1999 const std::string tmp =
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2000 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
2001 new_error_file = tmp;
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2002 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2003
21856
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2004 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
2005 {
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2006 const std::string tmp =
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2007 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
2008 new_error_name = tmp;
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2009 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2010
21856
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2011 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
2012 {
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2013 const int tmp =
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2014 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
2015 new_error_line = tmp;
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2016 }
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2017
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2018 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
2019 {
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2020 const int tmp =
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2021 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
2022 new_error_column = tmp;
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2023 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2024 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2025 }
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2026
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2027 Vlast_error_message = new_error_message;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2028 Vlast_error_id = new_error_id;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2029
21856
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2030 if (initialize_stack)
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2031 Vlast_error_stack = initialize_last_error_stack ();
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2032 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
2033 {
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2034 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
2035 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
2036 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
2037 new_err_stack.setfield ("column", new_error_column);
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2038 Vlast_error_stack = new_err_stack;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2039 }
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2040 else
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2041 {
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2042 // No stack field. Fill it in with backtrace info.
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2043 octave_idx_type curr_frame = -1;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2044
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
2045 octave::call_stack& cs = interp.get_call_stack ();
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
2046
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23465
diff changeset
2047 Vlast_error_stack = cs.backtrace (0, curr_frame);
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2048 }
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2049 }
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2050 else
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2051 error ("lasterror: argument must be a structure or a string");
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2052 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2053
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2054 return ovl (err);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2055 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 6338
diff changeset
2056
21856
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2057 /*
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2058 ## 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
2059 %!test
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2060 %! lasterror ("reset");
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2061 %! x = lasterror ();
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2062 %! assert (x.identifier, "")
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2063 %! assert (x.message, "")
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2064 %! assert (isempty (x.stack))
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2065 %! lasterror (x);
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2066 %! y = lasterror ();
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2067 %! assert (y, x);
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2068 */
c9c5340d4758 lasterror: Allow setting error state with an empty stack
Mike Miller <mtmiller@octave.org>
parents: 21751
diff changeset
2069
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2070 DEFUN (lasterr, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2071 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
2072 @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
2073 @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
2074 @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
2075 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
2076
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2077 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
2078 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
2079
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2080 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
2081
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2082 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
2083 @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
2084 @end deftypefn */)
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
2085 {
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2086 int nargin = args.length ();
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
2087
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2088 if (nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
2089 print_usage ();
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
2090
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2091 string_vector argv = args.make_argv ("lasterr");
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2092
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2093 std::string prev_error_id = Vlast_error_id;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2094 std::string prev_error_message = Vlast_error_message;
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2095
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2096 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
2097 {
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
2098 Vlast_error_id = argv[2];
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
2099 Vlast_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
2100 }
7883f240d8ea Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents: 20827
diff changeset
2101 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
2102 {
7883f240d8ea Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents: 20827
diff changeset
2103 Vlast_error_id = "";
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
2104 Vlast_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
2105 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2106
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2107 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
2108 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
2109 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
2110 return ovl ();
3935
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
2111 }
1ea29376e43e [project @ 2002-05-16 05:30:51 by jwe]
jwe
parents: 3934
diff changeset
2112
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2113 DEFUN (lastwarn, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2114 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
2115 @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
2116 @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
2117 @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
2118 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
2119
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2120 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
2121 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
2122
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2123 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
2124
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2125 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
2126 @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
2127 @end deftypefn */)
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
2128 {
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2129 int nargin = args.length ();
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2130
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2131 if (nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
2132 print_usage ();
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
2133
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2134 string_vector argv = args.make_argv ("lastwarn");
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2135
20803
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2136 std::string prev_warning_id = Vlast_warning_id;
c22206c1a88f eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2137 std::string prev_warning_message = Vlast_warning_message;
3934
31393822395b [project @ 2002-05-15 19:18:09 by jwe]
jwe
parents: 3815
diff changeset
2138
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2139 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
2140 {
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
2141 Vlast_warning_id = argv[2];
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
2142 Vlast_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
2143 }
7883f240d8ea Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents: 20827
diff changeset
2144 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
2145 {
7883f240d8ea Clear error/warning ID when lasterror/lastwarning called with just a message.
Rik <rik@octave.org>
parents: 20827
diff changeset
2146 Vlast_warning_id = "";
20996
20bd3d4fabad Clean up instances of make_argv().
Rik <rik@octave.org>
parents: 20980
diff changeset
2147 Vlast_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
2148 }
5567
80e629357483 [project @ 2005-12-07 06:31:28 by jwe]
jwe
parents: 5335
diff changeset
2149
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20803
diff changeset
2150 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
2151 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
2152 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
2153 return ovl ();
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
2154 }
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
2155
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2156 DEFUN (beep_on_error, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2157 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
2158 @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
2159 @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
2160 @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
2161 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
2162 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
2163
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2164 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
2165 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
2166 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
2167 @end deftypefn */)
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
2168 {
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2169 return SET_INTERNAL_VARIABLE (beep_on_error);
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
2170 }
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
2171
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2172 DEFUN (debug_on_error, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2173 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
2174 @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
2175 @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
2176 @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
2177 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
2178 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
2179
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2180 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
2181 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
2182
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2183 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
2184 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
2185 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
2186 @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
2187 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2188 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2189 return SET_INTERNAL_VARIABLE (debug_on_error);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2190 }
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
2191
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2192 DEFUN (debug_on_warning, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2193 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
2194 @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
2195 @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
2196 @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
2197 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
2198 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
2199
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
2200 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
2201 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
2202 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
2203 @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
2204 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2205 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5783
diff changeset
2206 return SET_INTERNAL_VARIABLE (debug_on_warning);
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
2207 }
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
2208
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
2209 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
2210 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
2211 {
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
2212 return Vlast_error_message;
065c28e1c368 Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents: 7976
diff changeset
2213 }
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
2214
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
2215 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
2216 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
2217 {
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
2218 return Vlast_error_id;
065c28e1c368 Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents: 7976
diff changeset
2219 }
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
2220
18222
6ef8b920a7d6 include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents: 18130
diff changeset
2221 octave_map
6ef8b920a7d6 include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents: 18130
diff changeset
2222 last_error_stack (void)
6ef8b920a7d6 include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents: 18130
diff changeset
2223 {
6ef8b920a7d6 include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents: 18130
diff changeset
2224 return Vlast_error_stack;
6ef8b920a7d6 include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents: 18130
diff changeset
2225 }
6ef8b920a7d6 include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents: 18130
diff changeset
2226
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
2227 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
2228 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
2229 {
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
2230 return Vlast_warning_message;
065c28e1c368 Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents: 7976
diff changeset
2231 }
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
2232
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
2233 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
2234 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
2235 {
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
2236 return Vlast_warning_id;
065c28e1c368 Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents: 7976
diff changeset
2237 }
11029
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2238
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2239 void
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
2240 interpreter_try (octave::unwind_protect& frame)
11029
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2241 {
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2242 frame.protect_var (buffer_error_messages);
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2243 frame.protect_var (Vdebug_on_error);
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2244 frame.protect_var (Vdebug_on_warning);
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2245
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2246 buffer_error_messages++;
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2247 Vdebug_on_error = false;
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2248 Vdebug_on_warning = false;
21157
94fc5f13d51b dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21127
diff changeset
2249 // leave Vdebug_on_caught as it was, so errors in try/catch are still caught
11029
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
2250 }