annotate libinterp/corefcn/error.cc @ 21966:112b20240c87

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