annotate libinterp/corefcn/error.cc @ 27160:6b0c61a5a0f0

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