annotate src/error.cc @ 3815:c554ad71bafc

[project @ 2001-04-19 19:50:52 by jwe]
author jwe
date Thu, 19 Apr 2001 19:50:54 +0000
parents 855bf76e1fe1
children 31393822395b
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
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2802
diff changeset
3 Copyright (C) 1996, 1997 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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
10 later version.
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1266
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 189
diff changeset
23 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1165
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
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3491
diff changeset
30 #include <strstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1633
diff changeset
31 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1633
diff changeset
32
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
33 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
34 #include "error.h"
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
35 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
36 #include "pager.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
37 #include "oct-obj.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
38 #include "utils.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2200
diff changeset
39 #include "ov.h"
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
40 #include "ov-usr-fcn.h"
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
41 #include "pt-pr-code.h"
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
42 #include "pt-stmt.h"
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
43 #include "toplev.h"
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
44 #include "unwind-prot.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2200
diff changeset
45 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
46
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
47 // 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
48 // error messages.
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
49 static bool Vbeep_on_error;
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
50
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
51 // 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
52 // 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
53 // traceback message (you will only see the top-level error message).
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
54 static bool Vdebug_on_error;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
55
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 a warning
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
57 // is encountered.
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
58 static bool Vdebug_on_warning;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
59
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 103
diff changeset
60 // Current error state.
672
066e1551639c [project @ 1994-09-07 21:10:32 by jwe]
jwe
parents: 610
diff changeset
61 int error_state = 0;
066e1551639c [project @ 1994-09-07 21:10:32 by jwe]
jwe
parents: 610
diff changeset
62
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3402
diff changeset
63 // Current warning state.
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3402
diff changeset
64 int warning_state = 0;
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3402
diff changeset
65
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
66 // 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
67 // them for later. Used for handling errors in eval() and
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
68 // the `unwind_protect' statement.
3136
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 3066
diff changeset
69 bool buffer_error_messages = false;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
70
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
71 // TRUE means error messages are turned off.
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
72 bool discard_error_messages = false;
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
73
3811
855bf76e1fe1 [project @ 2001-04-18 03:44:30 by jwe]
jwe
parents: 3764
diff changeset
74 // The message buffer.
855bf76e1fe1 [project @ 2001-04-18 03:44:30 by jwe]
jwe
parents: 3764
diff changeset
75 static std::ostrstream *error_message_buffer = 0;
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 103
diff changeset
76
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
77 // Warning messages are never buffered.
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
78 // XXX FIXME XXX -- we should provide another way to turn them off...
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
79
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
80 static void
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
81 vwarning (const char *name, const char *fmt, va_list args)
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
82 {
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
83 flush_octave_stdout ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
84
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
85 std::ostrstream output_buf;
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
86
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
87 if (name)
3761
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
88 output_buf << name << ": ";
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
89
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
90 octave_vformat (output_buf, fmt, args);
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
91
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
92 output_buf << std::endl << std::ends;
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
93
3761
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
94 char *msg = output_buf.str ();
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
95
3761
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
96 octave_diary << msg;
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
97 std::cerr << msg;
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
98
dfb1bfa12afd [project @ 2001-01-05 16:38:01 by jwe]
jwe
parents: 3719
diff changeset
99 delete [] msg;
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
100 }
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
101
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
102 static void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
103 verror (const char *name, const char *fmt, va_list args)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
104 {
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
105 if (discard_error_messages)
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
106 return;
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
107
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3548
diff changeset
108 if (! buffer_error_messages)
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3548
diff changeset
109 flush_octave_stdout ();
914
6a10b90623ea [project @ 1994-11-10 21:53:10 by jwe]
jwe
parents: 905
diff changeset
110
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
111 bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state;
1423
2d88758ed94b [project @ 1995-09-18 16:04:37 by jwe]
jwe
parents: 1363
diff changeset
112
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
113 std::ostrstream output_buf;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
114
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
115 if (to_beep_or_not_to_beep_p)
1423
2d88758ed94b [project @ 1995-09-18 16:04:37 by jwe]
jwe
parents: 1363
diff changeset
116 output_buf << "\a";
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3600
diff changeset
117
599
3ed5cf2aef94 [project @ 1994-08-12 04:20:27 by jwe]
jwe
parents: 581
diff changeset
118 if (name)
3ed5cf2aef94 [project @ 1994-08-12 04:20:27 by jwe]
jwe
parents: 581
diff changeset
119 output_buf << name << ": ";
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3600
diff changeset
120
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3600
diff changeset
121 octave_vformat (output_buf, fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3600
diff changeset
122
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3531
diff changeset
123 output_buf << std::endl << std::ends;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 528
diff changeset
124
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 528
diff changeset
125 char *msg = output_buf.str ();
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 528
diff changeset
126
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
127 if (buffer_error_messages)
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
128 {
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
129 char *ptr = msg;
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
130
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
131 if (! error_message_buffer)
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
132 {
3548
ab7fa5a8f23f [project @ 2000-02-03 01:17:15 by jwe]
jwe
parents: 3538
diff changeset
133 error_message_buffer = new std::ostrstream;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
134
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
135 // XXX FIXME XXX -- this is ugly, but it prevents
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
136 //
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
137 // eval ("error (\"msg\")", "error (__error_text__)");
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
138 //
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
139 // from printing `error: ' twice. Assumes that the NAME we
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
140 // have been given doesn't contain `:'.
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
141
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
142 ptr = strchr (msg, ':');
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
143
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
144 if (ptr)
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
145 {
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
146 if (*++ptr != '\0')
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
147 ++ptr;
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
148 }
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
149 else
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3141
diff changeset
150 ptr = msg;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
151 }
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
152
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
153 *error_message_buffer << ptr;
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
154 }
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
155 else
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
156 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
157 octave_diary << msg;
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
158 std::cerr << msg;
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
159 }
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 528
diff changeset
160
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 528
diff changeset
161 delete [] msg;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
162 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
163
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
164 // Note that we don't actually print any message if the error string
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
165 // is just "" or "\n". This allows error ("") and error ("\n") to
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
166 // just set the error state.
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
167
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
168 static void
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
169 error_1 (const char *name, const char *fmt, va_list args)
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
170 {
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
171 if (error_state != -2)
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
172 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
173 if (fmt)
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
174 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
175 if (*fmt)
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
176 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
177 int len = strlen (fmt);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
178 if (fmt[len - 1] == '\n')
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
179 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
180 if (len > 1)
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
181 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
182 char *tmp_fmt = strsave (fmt);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
183 tmp_fmt[len - 1] = '\0';
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
184 verror (name, tmp_fmt, args);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
185 delete [] tmp_fmt;
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
186 }
1423
2d88758ed94b [project @ 1995-09-18 16:04:37 by jwe]
jwe
parents: 1363
diff changeset
187
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
188 error_state = -2;
1266
e1ddfb12566d [project @ 1995-04-20 18:56:04 by jwe]
jwe
parents: 1192
diff changeset
189 }
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
190 else
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
191 verror (name, fmt, args);
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
192 }
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
193 }
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
194 else
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
195 panic ("error_1: invalid format");
1423
2d88758ed94b [project @ 1995-09-18 16:04:37 by jwe]
jwe
parents: 1363
diff changeset
196
2d88758ed94b [project @ 1995-09-18 16:04:37 by jwe]
jwe
parents: 1363
diff changeset
197 if (! error_state)
2d88758ed94b [project @ 1995-09-18 16:04:37 by jwe]
jwe
parents: 1363
diff changeset
198 error_state = 1;
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
199 }
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
200 }
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
201
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
202 void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
203 message (const char *name, const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
204 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
205 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
206 va_start (args, fmt);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
207 verror (name, fmt, args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
208 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
209 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
210
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
211 void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
212 usage (const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
213 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
214 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
215 va_start (args, fmt);
905
0f3237aa35b7 [project @ 1994-11-09 21:49:34 by jwe]
jwe
parents: 899
diff changeset
216 error_state = -1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
217 verror ("usage", fmt, args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
218 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
219 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
220
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
221 static void
3719
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
222 pr_where_2 (const char *fmt, va_list args)
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
223 {
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
224 if (fmt)
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
225 {
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
226 if (*fmt)
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
227 {
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
228 int len = strlen (fmt);
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
229 if (fmt[len - 1] == '\n')
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
230 {
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
231 if (len > 1)
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
232 {
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
233 char *tmp_fmt = strsave (fmt);
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
234 tmp_fmt[len - 1] = '\0';
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
235 verror (0, tmp_fmt, args);
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
236 delete [] tmp_fmt;
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
237 }
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
238 }
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
239 else
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
240 verror (0, fmt, args);
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
241 }
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
242 }
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
243 else
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
244 panic ("pr_where_2: invalid format");
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
245 }
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
246
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
247 static void
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
248 pr_where_1 (const char *fmt, ...)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
249 {
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
250 va_list args;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
251 va_start (args, fmt);
3719
744755872311 [project @ 2000-10-10 21:42:20 by jwe]
jwe
parents: 3708
diff changeset
252 pr_where_2 (fmt, args);
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
253 va_end (args);
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
254 }
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
255
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
256 static void
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
257 pr_where (const char *name)
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
258 {
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
259 if (curr_statement)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
260 {
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
261 const char *f_nm = 0;
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
262
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
263 if (curr_function)
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
264 {
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
265 std::string fcn_name = curr_function->function_name ();
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
266 std::string file_name = curr_function->fcn_file_name ();
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
267
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
268 f_nm = file_name.empty () ? fcn_name.c_str () : file_name.c_str ();
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
269 }
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
270
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
271 int l = curr_statement->line ();
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
272 int c = curr_statement->column ();
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
273
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
274 if (f_nm)
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
275 pr_where_1 ("%s: in %s near line %d, column %d:", name, f_nm, l, c);
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
276 else
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
277 pr_where_1 ("%s: near line %d, column %d:", name, l, c);
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
278
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
279 // XXX FIXME XXX -- Note that the column number is probably not
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
280 // going to mean much here since the code is being reproduced
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
281 // from the parse tree, and we are only showing one statement
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
282 // even if there were multiple statements on the original source
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
283 // line.
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
284
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
285 std::ostrstream output_buf;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
286
3764
0ac9388e7e1f [project @ 2001-01-17 03:41:39 by jwe]
jwe
parents: 3761
diff changeset
287 output_buf << std::endl;
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
288
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
289 tree_print_code tpc (output_buf, ">>> ");
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
290
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
291 curr_statement->accept (tpc);
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
292
3764
0ac9388e7e1f [project @ 2001-01-17 03:41:39 by jwe]
jwe
parents: 3761
diff changeset
293 output_buf << std::endl << std::ends;
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
294
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
295 char *msg = output_buf.str ();
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
296
3764
0ac9388e7e1f [project @ 2001-01-17 03:41:39 by jwe]
jwe
parents: 3761
diff changeset
297 pr_where_1 ("%s", msg);
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
298
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
299 delete [] msg;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
300 }
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
301 }
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
302
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
303 void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
304 warning (const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
305 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
306 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
307 va_start (args, fmt);
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3402
diff changeset
308 warning_state = 1;
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
309 vwarning ("warning", fmt, args);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
310 va_end (args);
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
311
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
312 pr_where ("warning");
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
313
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
314 if ((interactive || forced_interactive)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
315 && Vdebug_on_warning && curr_function)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
316 {
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
317 unwind_protect_bool (Vdebug_on_warning);
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
318 Vdebug_on_warning = false;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
319
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
320 do_keyboard (octave_value_list ());
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
321
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
322 unwind_protect::run ();
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
323 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
324 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
325
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
326 void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
327 error (const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
328 {
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
329 int init_state = error_state;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
330
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
331 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
332 va_start (args, fmt);
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
333 error_1 ("error", fmt, args);
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
334 va_end (args);
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
335
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
336 if ((interactive || forced_interactive)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
337 && Vdebug_on_error && init_state == 0 && curr_function)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
338 {
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
339 unwind_protect_bool (Vdebug_on_error);
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
340 Vdebug_on_error = false;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
341
3708
9b9efdcbdfd3 [project @ 2000-07-28 20:50:58 by jwe]
jwe
parents: 3707
diff changeset
342 pr_where ("error");
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
343
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
344 error_state = 0;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
345
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
346 do_keyboard (octave_value_list ());
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
347
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
348 unwind_protect::run ();
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
349 }
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
350 }
436
f7314b67a142 [project @ 1994-05-26 00:44:37 by jwe]
jwe
parents: 240
diff changeset
351
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
352 void
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
353 parse_error (const char *fmt, ...)
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
354 {
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
355 va_list args;
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
356 va_start (args, fmt);
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 914
diff changeset
357 error_1 (0, fmt, args);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
358 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
359 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
360
189
de0e58f9b064 [project @ 1993-10-28 08:52:15 by jwe]
jwe
parents: 169
diff changeset
361 void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
362 panic (const char *fmt, ...)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
363 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
364 va_list args;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
365 va_start (args, fmt);
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3548
diff changeset
366 buffer_error_messages = false;
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3811
diff changeset
367 discard_error_messages = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
368 verror ("panic", fmt, args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
369 va_end (args);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
370 abort ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
371 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
372
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
373 typedef void (*error_fun)(const char *, ...);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
374
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
375 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
376
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
377 static octave_value_list
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
378 handle_message (error_fun f, const char *msg, const octave_value_list& args)
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
379 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
380 octave_value_list retval;
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
381
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
382 std::string tstr;
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1633
diff changeset
383
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
384 int nargin = args.length ();
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
385
2745
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
386 if (nargin > 0)
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
387 {
3066
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
388 octave_value arg;
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
389
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
390 if (nargin > 1)
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
391 {
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
392 octave_value_list tmp = Fsprintf (args, 1);
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
393 arg = tmp(0);
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
394 }
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
395 else
2d485faf2fa3 [project @ 1997-07-02 21:48:29 by jwe]
jwe
parents: 3018
diff changeset
396 arg = args(0);
2745
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
397
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
398 if (arg.is_defined ())
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
399 {
2745
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
400 if (arg.is_string ())
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
401 {
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
402 tstr = arg.string_value ();
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
403 msg = tstr.c_str ();
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
404
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
405 if (! msg)
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
406 return retval;
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
407 }
76411ce43c05 [project @ 1997-02-26 07:52:14 by jwe]
jwe
parents: 2620
diff changeset
408 else if (arg.is_empty ())
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
409 return retval;
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
410 }
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
411 }
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
412
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
413 // Ugh.
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
414
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
415 int len = strlen (msg);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
416 if (msg[len - 1] == '\n')
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
417 {
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
418 if (len > 1)
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
419 {
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
420 char *tmp_msg = strsave (msg);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
421 tmp_msg[len - 1] = '\0';
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
422 f ("%s\n", tmp_msg);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
423 delete [] tmp_msg;
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
424 }
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
425 }
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
426 else
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
427 f ("%s", msg);
528
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
428
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
429 return retval;
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
430 }
e1e6e33e26f8 [project @ 1994-07-20 18:53:50 by jwe]
jwe
parents: 514
diff changeset
431
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
432 DEFUN (error, args, ,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
433 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
434 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
435 The @code{error} function formats the optional arguments under the\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
436 control of the template string @var{template} using the same rules as\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
437 the @code{printf} family of functions (@pxref{Formatted Output}).\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
438 The resulting message is prefixed by the string @samp{error: } and\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
439 printed on the @code{stderr} stream.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
440 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
441 Calling @code{error} also sets Octave's internal error state such that\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
442 control will return to the top level without evaluating any more\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
443 commands. This is useful for aborting from functions or scripts.\n\
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
444 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
445 If the error message does not end with a new line character, Octave will\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
446 print a traceback of all the function calls leading to the error. For\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
447 example, given the following function definitions:\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
448 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
449 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
450 @group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
451 function f () g () end\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
452 function g () h () end\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
453 function h () nargin == 1 || error (\"nargin != 1\"); end\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
454 @end group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
455 @end example\n\
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
456 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
457 @noindent\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
458 calling the function @code{f} will result in a list of messages that\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
459 can help you to quickly locate the exact location of the error:\n\
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
460 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
461 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
462 @group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
463 f ()\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
464 error: nargin != 1\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
465 error: evaluating index expression near line 1, column 30\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
466 error: evaluating binary operator `||' near line 1, column 27\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
467 error: called from `h'\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
468 error: called from `g'\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
469 error: called from `f'\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
470 @end group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
471 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
472 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
473 If the error message ends in a new line character, Octave will print the\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
474 message but will not display any traceback messages as it returns\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
475 control to the top level. For example, modifying the error message\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
476 in the previous example to end in a new line causes Octave to only print\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
477 a single message:\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
478 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
479 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
480 @group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
481 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
482 f ()\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
483 error: nargin != 1\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
484 @end group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
485 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
486 @end deftypefn")
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
487 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
488 return handle_message (error, "unspecified error", args);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
489 }
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
490
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
491 DEFUN (warning, args, ,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
492 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
493 @deftypefn {Built-in Function} {} warning (@var{msg})\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
494 Print a warning message @var{msg} prefixed by the string @samp{warning: }. \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
495 After printing the warning message, Octave will continue to execute\n\
3600
c11d138d654a [project @ 2000-02-24 03:55:32 by jwe]
jwe
parents: 3585
diff changeset
496 commands. You should use this function when you want to notify the user\n\
c11d138d654a [project @ 2000-02-24 03:55:32 by jwe]
jwe
parents: 3585
diff changeset
497 of an unusual condition, but only when it makes sense for your program\n\
c11d138d654a [project @ 2000-02-24 03:55:32 by jwe]
jwe
parents: 3585
diff changeset
498 to go on.\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
499 @end deftypefn")
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
500 {
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
501 return handle_message (warning, "unspecified warning", args);
897
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
502 }
54921d080295 [project @ 1994-11-09 18:01:33 by jwe]
jwe
parents: 729
diff changeset
503
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
504 DEFUN (usage, args, ,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
505 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
506 @deftypefn {Built-in Function} {} usage (@var{msg})\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
507 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
508 set Octave's internal error state such that control will return to the\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
509 top level without evaluating any more commands. This is useful for\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
510 aborting from functions.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
511 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
512 After @code{usage} is evaluated, Octave will print a traceback of all\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
513 the function calls leading to the usage message.\n\
899
00e903c95534 [project @ 1994-11-09 18:06:56 by jwe]
jwe
parents: 897
diff changeset
514 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
515 You should use this function for reporting problems errors that result\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
516 from an improper call to a function, such as calling a function with an\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
517 incorrect number of arguments, or with arguments of the wrong type. For\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
518 example, most functions distributed with Octave begin with code like\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
519 this\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
520 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
521 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
522 @group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
523 if (nargin != 2)\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
524 usage (\"foo (a, b)\");\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
525 endif\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
526 @end group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
527 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
528 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
529 @noindent\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
530 to check for the proper number of arguments.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
531 @end deftypefn")
899
00e903c95534 [project @ 1994-11-09 18:06:56 by jwe]
jwe
parents: 897
diff changeset
532 {
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
533 return handle_message (usage, "unknown", args);
899
00e903c95534 [project @ 1994-11-09 18:06:56 by jwe]
jwe
parents: 897
diff changeset
534 }
00e903c95534 [project @ 1994-11-09 18:06:56 by jwe]
jwe
parents: 897
diff changeset
535
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
536 void
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
537 bind_global_error_variable (void)
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
538 {
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
539 if (error_message_buffer)
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
540 {
3538
0ff7323dab8b [project @ 2000-02-02 12:36:25 by jwe]
jwe
parents: 3531
diff changeset
541 *error_message_buffer << std::ends;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
542
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
543 char *error_text = error_message_buffer->str ();
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
544
3811
855bf76e1fe1 [project @ 2001-04-18 03:44:30 by jwe]
jwe
parents: 3764
diff changeset
545 bind_builtin_variable ("__error_text__", error_text, true);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
546
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
547 delete [] error_text;
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
548
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
549 delete error_message_buffer;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
550
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
551 error_message_buffer = 0;
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
552 }
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3489
diff changeset
553 else
3811
855bf76e1fe1 [project @ 2001-04-18 03:44:30 by jwe]
jwe
parents: 3764
diff changeset
554 bind_builtin_variable ("__error_text__", "", true);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
555 }
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
556
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
557 void
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
558 clear_global_error_variable (void *)
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
559 {
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
560 delete error_message_buffer;
3811
855bf76e1fe1 [project @ 2001-04-18 03:44:30 by jwe]
jwe
parents: 3764
diff changeset
561
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
562 error_message_buffer = 0;
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
563
3811
855bf76e1fe1 [project @ 2001-04-18 03:44:30 by jwe]
jwe
parents: 3764
diff changeset
564 bind_builtin_variable ("__error_text__", "", true);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
565 }
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
566
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
567 static int
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
568 beep_on_error (void)
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
569 {
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
570 Vbeep_on_error = check_preference ("beep_on_error");
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
571
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
572 return 0;
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
573 }
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
574
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
575 static int
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
576 debug_on_error (void)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
577 {
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
578 Vdebug_on_error = check_preference ("debug_on_error");
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
579
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
580 return 0;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
581 }
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
582
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
583 static int
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
584 debug_on_warning (void)
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
585 {
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
586 Vdebug_on_warning = check_preference ("debug_on_warning");
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
587
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
588 return 0;
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
589 }
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
590
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
591 void
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
592 symbols_of_error (void)
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
593 {
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3162
diff changeset
594 DEFVAR (beep_on_error, 0.0, beep_on_error,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
595 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
596 @defvr {Built-in Variable} beep_on_error\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
597 If the value of @code{beep_on_error} is nonzero, Octave will try\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
598 to ring your terminal's bell before printing an error message. The\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
599 default value is 0.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
600 @end defvr");
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2847
diff changeset
601
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
602 DEFVAR (debug_on_error, 0.0, debug_on_error,
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
603 "-*- texinfo -*-\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
604 @defvr {Built-in Variable} debug_on_error\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
605 If the value of @code{debug_on_error} is nonzero, Octave will try\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
606 to enter the debugger when an error is encountered. This will also\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
607 inhibit printing of the normal traceback message (you will only see\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
608 the top-level error message). The default value is 0.\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
609 @end defvr");
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
610
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
611 DEFVAR (debug_on_warning, 0.0, debug_on_warning,
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
612 "-*- texinfo -*-\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
613 @defvr {Built-in Variable} debug_on_warning\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
614 If the value of @code{debug_on_warning} is nonzero, Octave will try\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
615 to enter the debugger when a warning is encountered. The default\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
616 value is 0.\n\
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
617 @end defvr");
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3620
diff changeset
618
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 3136
diff changeset
619 DEFCONST (error_text, "",
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
620 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
621 @defvr {Built-in Variable} error_text\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
622 This variable contains the text of error messages that would have\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
623 been printed in the body of the most recent @code{unwind_protect} or\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
624 @code{try} statement or the @var{try} part of the most recent call to\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
625 the @code{eval} function. Outside of the @code{unwind_protect} and\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
626 @code{try} statements or the @code{eval} function, or if no error has\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
627 occurred within them, the value of @code{error_text} is guaranteed to be\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
628 the empty string.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
629 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
630 Note that the message does not include the first @samp{error: } prefix,\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
631 so that it may easily be passed to the @code{error} function without\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
632 additional processing@footnote{Yes, it's a kluge, but it seems to be a\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
633 reasonably useful one.}.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
634 \n\
3402
9610d364e444 [project @ 2000-01-05 04:36:38 by jwe]
jwe
parents: 3373
diff changeset
635 @xref{The try Statement}, and @ref{The unwind_protect Statement}.\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3259
diff changeset
636 @end defvr");
2174
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
637 }
68b02495a5ac [project @ 1996-05-13 16:08:39 by jwe]
jwe
parents: 2095
diff changeset
638
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
639 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
640 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
641 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
642 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
643 */