annotate libinterp/corefcn/error.cc @ 28981:d632d99d5c2e

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