-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherror.cc
1840 lines (1541 loc) · 48.3 KB
/
error.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1993-2011 John W. Eaton
This file is part of Octave.
Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#include <cstdarg>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
/*#include "defun.h"
#include "error.h"
#include "input.h"
#include "pager.h"
#include "oct-obj.h"
#include "oct-map.h"
#include "utils.h"
#include "ov.h"
#include "ov-usr-fcn.h"
#include "pt-pr-code.h"
#include "pt-stmt.h"
#include "toplev.h"
#include "unwind-prot.h"
#include "variables.h"
*/
// TRUE means that Octave will try to beep obnoxiously before printing
// error messages.
static bool Vbeep_on_error = false;
// TRUE means that Octave will try to enter the debugger when an error
// is encountered. This will also inhibit printing of the normal
// traceback message (you will only see the top-level error message).
bool Vdebug_on_error = false;
// TRUE means that Octave will try to enter the debugger when a warning
// is encountered.
bool Vdebug_on_warning = false;
// TRUE means that Octave will try to display a stack trace when a
// warning is encountered.
static bool Vbacktrace_on_warning = false;
// TRUE means that Octave will print a verbose warning. Currently unused.
static bool Vverbose_warning;
// TRUE means that Octave will print no warnings, but lastwarn will be
//updated
static bool Vquiet_warning = false;
// A structure containing (most of) the current state of warnings.
//static octave_map warning_options;
// The text of the last error message.
static std::string Vlast_error_message;
// The text of the last warning message.
static std::string Vlast_warning_message;
// The last warning message id.
static std::string Vlast_warning_id;
// The last error message id.
static std::string Vlast_error_id;
// The last file in which an error occured
//static octave_map Vlast_error_stack;
// Current error state.
//
// Valid values:
//
// -2: an error has occurred, but don't print any messages.
// -1: an error has occurred, we are printing a traceback
// 0: no error
// 1: an error has occurred
//
int error_state = 0;
// Current warning state.
//
// Valid values:
//
// 0: no warning
// 1: a warning has occurred
//
int warning_state = 0;
// Tell the error handler whether to print messages, or just store
// them for later. Used for handling errors in eval() and
// the `unwind_protect' statement.
int buffer_error_messages = 0;
// TRUE means error messages are turned off.
bool discard_error_messages = false;
// TRUE means warning messages are turned off.
bool discard_warning_messages = false;
// The message buffer.
static std::ostringstream *error_message_buffer = 0;
/*void
reset_error_handler (void)
{
error_state = 0;
warning_state = 0;
buffer_error_messages = 0;
discard_error_messages = false;
}
static void
initialize_warning_options (const std::string& state)
{
octave_scalar_map initw;
initw.setfield ("identifier", "all");
initw.setfield ("state", state);
warning_options = initw;
}
static octave_map
initialize_last_error_stack (void)
{
return octave_call_stack::empty_backtrace ();
}
// Warning messages are never buffered.
static void
vwarning (const char *name, const char *id, const char *fmt, va_list args)
{
if (discard_warning_messages)
return;
flush_octave_stdout ();
std::ostringstream output_buf;
if (name)
output_buf << name << ": ";
octave_vformat (output_buf, fmt, args);
output_buf << std::endl;
// FIXME -- we really want to capture the message before it
// has all the formatting goop attached to it. We probably also
// want just the message, not the traceback information.
std::string msg_string = output_buf.str ();
if (! warning_state)
{
// This is the first warning in a possible series.
Vlast_warning_id = id;
Vlast_warning_message = msg_string;
}
if (! Vquiet_warning)
{
octave_diary << msg_string;
std::cerr << msg_string;
}
}
static void
verror (bool save_last_error, std::ostream& os,
const char *name, const char *id, const char *fmt, va_list args,
bool with_cfn = false)
{
if (discard_error_messages)
return;
if (! buffer_error_messages)
flush_octave_stdout ();
// FIXME -- we really want to capture the message before it
// has all the formatting goop attached to it. We probably also
// want just the message, not the traceback information.
std::ostringstream output_buf;
octave_vformat (output_buf, fmt, args);
std::string base_msg = output_buf.str ();
bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state;
std::string msg_string;
if (to_beep_or_not_to_beep_p)
msg_string = "\a";
if (name)
msg_string += std::string (name) + ": ";
// If with_fcn is specified, we'll attempt to prefix the message with the name
// of the current executing function. But we'll do so only if:
// 1. the name is not empty (anonymous function)
// 2. it is not already there (including the following colon)
if (with_cfn)
{
octave_function *curfcn = octave_call_stack::current ();
if (curfcn)
{
std::string cfn = curfcn->name ();
if (! cfn.empty ())
{
cfn += ':';
if (cfn.length () > base_msg.length ()
|| base_msg.compare (0, cfn.length (), cfn) != 0)
{
msg_string += cfn + ' ';
}
}
}
}
msg_string += base_msg + "\n";
if (! error_state && save_last_error)
{
// This is the first error in a possible series.
Vlast_error_id = id;
Vlast_error_message = base_msg;
octave_user_code *fcn = octave_call_stack::caller_user_code ();
if (fcn)
{
octave_idx_type curr_frame = -1;
Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame);
}
else
Vlast_error_stack = initialize_last_error_stack ();
}
if (buffer_error_messages)
{
if (error_message_buffer)
msg_string = "error: " + msg_string;
else
error_message_buffer = new std::ostringstream ();
*error_message_buffer << msg_string;
}
else
{
octave_diary << msg_string;
os << msg_string;
}
}
// Note that we don't actually print any message if the error string
// is just "" or "\n". This allows error ("") and error ("\n") to
// just set the error state.
static void
error_1 (std::ostream& os, const char *name, const char *id,
const char *fmt, va_list args, bool with_cfn = false)
{
if (error_state != -2)
{
if (fmt)
{
if (*fmt)
{
size_t len = strlen (fmt);
if (len > 0)
{
if (fmt[len - 1] == '\n')
{
if (len > 1)
{
char *tmp_fmt = strdup (fmt);
tmp_fmt[len - 1] = '\0';
//verror (true, os, name, id, tmp_fmt, args, with_cfn);
error("ERROR");
delete [] tmp_fmt;
}
error_state = -2;
}
else
{
//verror (true, os, name, id, fmt, args, with_cfn);
error("ERROR");
if (! error_state)
error_state = 1;
}
}
}
}
else
panic ("error_1: invalid format");
}
}
void
vmessage (const char *name, const char *fmt, va_list args)
{
verror (false, std::cerr, name, "", fmt, args);
}
void
message (const char *name, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vmessage (name, fmt, args);
va_end (args);
}
void
vmessage_with_id (const char *name, const char *id, const char *fmt,
va_list args)
{
verror (false, std::cerr, name, id, fmt, args);
}
void
message_with_id (const char *name, const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vmessage_with_id (name, id, fmt, args);
va_end (args);
}
void
usage_1 (const char *id, const char *fmt, va_list args)
{
verror (true, std::cerr, "usage", id, fmt, args);
error_state = -1;
}
void
vusage (const char *fmt, va_list args)
{
usage_1 ("", fmt, args);
}
void
usage (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vusage (fmt, args);
va_end (args);
}
void
vusage_with_id (const char *id, const char *fmt, va_list args)
{
usage_1 (id, fmt, args);
}
void
usage_with_id (const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vusage_with_id (id, fmt, args);
va_end (args);
}
static void
pr_where_2 (const char *fmt, va_list args)
{
if (fmt)
{
if (*fmt)
{
size_t len = strlen (fmt);
if (len > 0)
{
if (fmt[len - 1] == '\n')
{
if (len > 1)
{
char *tmp_fmt = strsave (fmt);
tmp_fmt[len - 1] = '\0';
verror (false, std::cerr, 0, "", tmp_fmt, args);
delete [] tmp_fmt;
}
}
else
verror (false, std::cerr, 0, "", fmt, args);
}
}
}
else
panic ("pr_where_2: invalid format");
}
static void
pr_where_1 (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
pr_where_2 (fmt, args);
va_end (args);
}
static void
pr_where (const char *who)
{
octave_idx_type curr_frame = -1;
octave_map stk = octave_call_stack::backtrace (0, curr_frame);
octave_idx_type nframes_to_display = stk.numel ();
if (nframes_to_display > 0)
{
pr_where_1 ("%s: called from\n", who);
Cell names = stk.contents ("name");
Cell lines = stk.contents ("line");
Cell columns = stk.contents ("column");
for (octave_idx_type i = 0; i < nframes_to_display; i++)
{
octave_value name = names(i);
octave_value line = lines(i);
octave_value column = columns(i);
std::string nm = name.string_value ();
pr_where_1 (" %s at line %d column %d\n", nm.c_str (),
line.int_value (), column.int_value ());
}
}
}
*/
void error (const char *fmt, ...);
static void
error_2 (const char *id, const char *fmt, va_list args, bool with_cfn = false)
{
//int init_state = error_state;
//error_1 (std::cerr, "error", id, fmt, args, with_cfn);
//error("ERROR");
// if ((interactive || forced_interactive)
// && Vdebug_on_error && init_state == 0
// && octave_call_stack::caller_user_code ())
// {
// unwind_protect frame;
// frame.protect_var (Vdebug_on_error);
// Vdebug_on_error = false;
// error_state = 0;
// pr_where ("error");
// do_keyboard (octave_value_list ());
// }
}
void
verror (const char *fmt, va_list args)
{
error_2 ("", fmt, args);
}
void
error (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
verror (fmt, args);
va_end (args);
}
/*void
verror_with_cfn (const char *fmt, va_list args)
{
error_2 ("", fmt, args, true);
}
void
error_with_cfn (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
verror_with_cfn (fmt, args);
va_end (args);
}
void
verror_with_id (const char *id, const char *fmt, va_list args)
{
error_2 (id, fmt, args);
}
void
error_with_id (const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
verror_with_id (id, fmt, args);
va_end (args);
}
void
verror_with_id_cfn (const char *id, const char *fmt, va_list args)
{
error_2 (id, fmt, args, true);
}
void
error_with_id_cfn (const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
verror_with_id_cfn (id, fmt, args);
va_end (args);
}
static int
check_state (const std::string& state)
{
// -1: not found
// 0: found, "off"
// 1: found, "on"
// 2: found, "error"
if (state == "off")
return 0;
else if (state == "on")
return 1;
else if (state == "error")
return 2;
else
return -1;
}
// For given warning ID, return 0 if warnings are disabled, 1 if
// enabled, and 2 if this ID should be an error instead of a warning.
int
warning_enabled (const std::string& id)
{
int retval = 0;
int all_state = -1;
int id_state = -1;
octave_idx_type nel = warning_options.numel ();
if (nel > 0)
{
Cell identifier = warning_options.contents ("identifier");
Cell state = warning_options.contents ("state");
bool all_found = false;
bool id_found = false;
for (octave_idx_type i = 0; i < nel; i++)
{
octave_value ov = identifier(i);
std::string ovs = ov.string_value ();
if (! all_found && ovs == "all")
{
all_state = check_state (state(i).string_value ());
if (all_state >= 0)
all_found = true;
}
if (! id_found && ovs == id)
{
id_state = check_state (state(i).string_value ());
if (id_state >= 0)
id_found = true;
}
if (all_found && id_found)
break;
}
}
if (all_state == -1)
panic_impossible ();
if (all_state == 0)
{
if (id_state >= 0)
retval = id_state;
}
else if (all_state == 1)
{
if (id_state == 0 || id_state == 2)
retval = id_state;
else
retval = all_state;
}
else if (all_state == 2)
{
if (id_state == 0)
retval= id_state;
else
retval = all_state;
}
return retval;
}
*/
static void
warning_1 (const char *id, const char *fmt, va_list args)
{
// int warn_opt = warning_enabled (id);
// if (warn_opt == 2)
// {
// Handle this warning as an error.
std::cerr << "Warning";
// }
// else if (warn_opt == 1)
// {
// vwarning ("warning", id, fmt, args);
// if (! symbol_table::at_top_level ()
// && Vbacktrace_on_warning
// && ! warning_state
// && ! discard_warning_messages)
// pr_where ("warning");
// warning_state = 1;
// if ((interactive || forced_interactive)
// && Vdebug_on_warning
// && octave_call_stack::caller_user_code ())
// {
// unwind_protect frame;
// frame.protect_var (Vdebug_on_warning);
// Vdebug_on_warning = false;
// do_keyboard (octave_value_list ());
// }
// }
}
void
vwarning (const char *fmt, va_list args)
{
warning_1 ("", fmt, args);
}
void
warning (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vwarning (fmt, args);
va_end (args);
}
void
vwarning_with_id (const char *id, const char *fmt, va_list args)
{
warning_1 (id, fmt, args);
}
void
warning_with_id (const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vwarning_with_id (id, fmt, args);
va_end (args);
}
/*
void
vparse_error (const char *fmt, va_list args)
{
error_1 (std::cerr, 0, "", fmt, args);
}
void
parse_error (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vparse_error (fmt, args);
va_end (args);
}
void
vparse_error_with_id (const char *id, const char *fmt, va_list args)
{
error_1 (std::cerr, 0, id, fmt, args);
}
void
parse_error_with_id (const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vparse_error_with_id (id, fmt, args);
va_end (args);
}
void
rethrow_error (const char *id, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
error_1 (std::cerr, 0, id, fmt, args);
va_end (args);
}
*/
void
panic (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
buffer_error_messages = 0;
discard_error_messages = false;
verror (fmt, args);
va_end (args);
//abort ();
}
/*
static void
defun_usage_message_1 (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
error_1 (octave_stdout, 0, "", fmt, args);
va_end (args);
}
void
defun_usage_message (const std::string& msg)
{
defun_usage_message_1 ("%s", msg.c_str ());
}
typedef void (*error_fun)(const char *, const char *, ...);
extern octave_value_list Fsprintf (const octave_value_list&, int);
static std::string
handle_message (error_fun f, const char *id, const char *msg,
const octave_value_list& args)
{
std::string retval;
std::string tstr;
int nargin = args.length ();
if (nargin > 0)
{
octave_value arg;
if (nargin > 1)
{
octave_value_list tmp = Fsprintf (args, 1);
arg = tmp(0);
}
else
arg = args(0);
if (arg.is_defined ())
{
if (arg.is_string ())
{
tstr = arg.string_value ();
msg = tstr.c_str ();
if (! msg)
return retval;
}
else if (arg.is_empty ())
return retval;
}
}
// Ugh.
size_t len = strlen (msg);
if (len > 0)
{
if (msg[len - 1] == '\n')
{
if (len > 1)
{
char *tmp_msg = strsave (msg);
tmp_msg[len - 1] = '\0';
f (id, "%s\n", tmp_msg);
retval = tmp_msg;
delete [] tmp_msg;
}
}
else
{
f (id, "%s", msg);
retval = msg;
}
}
return retval;
}
DEFUN (rethrow, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} rethrow (@var{err})\n\
Reissue a previous error as defined by @var{err}. @var{err} is a structure\n\
that must contain at least the 'message' and 'identifier' fields. @var{err}\n\
can also contain a field 'stack' that gives information on the assumed\n\
location of the error. Typically @var{err} is returned from\n\
@code{lasterror}.\n\
@seealso{lasterror, lasterr, error}\n\
@end deftypefn")
{
octave_value retval;
int nargin = args.length();
if (nargin != 1)
print_usage ();
else
{
const octave_scalar_map err = args(0).scalar_map_value ();
if (! error_state)
{
if (err.contains ("message") && err.contains ("identifier"))
{
std::string msg = err.contents("message").string_value ();
std::string id = err.contents("identifier").string_value ();
int len = msg.length();
std::string file;
std::string nm;
int l = -1;
int c = -1;
octave_map err_stack = initialize_last_error_stack ();
if (err.contains ("stack"))
{
err_stack = err.contents("stack").map_value ();
if (err_stack.numel () > 0)
{
if (err_stack.contains ("file"))
file = err_stack.contents("file")(0).string_value ();
if (err_stack.contains ("name"))
nm = err_stack.contents("name")(0).string_value ();
if (err_stack.contains ("line"))
l = err_stack.contents("line")(0).nint_value ();
if (err_stack.contains ("column"))
c = err_stack.contents("column")(0).nint_value ();
}
}
// Ugh.
char *tmp_msg = strsave (msg.c_str ());
if (tmp_msg[len-1] == '\n')
{
if (len > 1)
{
tmp_msg[len - 1] = '\0';
rethrow_error (id.c_str (), "%s\n", tmp_msg);
}
}
else
rethrow_error (id.c_str (), "%s", tmp_msg);
delete [] tmp_msg;
// FIXME -- is this the right thing to do for
// Vlast_error_stack? Should it be saved and restored
// with unwind_protect?
Vlast_error_stack = err_stack;
if (err.contains ("stack"))
{
if (file.empty ())
{
if (nm.empty ())
{
if (l > 0)
{
if (c > 0)
pr_where_1 ("error: near line %d, column %d",
l, c);
else
pr_where_1 ("error: near line %d", l);
}
}
else
{
if (l > 0)
{
if (c > 0)
pr_where_1 ("error: called from `%s' near line %d, column %d",
nm.c_str (), l, c);
else
pr_where_1 ("error: called from `%d' near line %d", nm.c_str (), l);
}
}
}
else
{
if (nm.empty ())
{
if (l > 0)
{
if (c > 0)
pr_where_1 ("error: in file %s near line %d, column %d",
file.c_str (), l, c);
else
pr_where_1 ("error: in file %s near line %d", file.c_str (), l);
}
}
else
{
if (l > 0)
{
if (c > 0)
pr_where_1 ("error: called from `%s' in file %s near line %d, column %d",
nm.c_str (), file.c_str (), l, c);
else
pr_where_1 ("error: called from `%d' in file %s near line %d", nm.c_str (), file.c_str (), l);
}
}
}
}
}
else
error ("rethrow: ERR structure must contain the fields 'message and 'identifier'");
}
}
return retval;
}
DEFUN (error, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\
@deftypefnx {Built-in Function} {} error (@var{id}, @var{template}, @dots{})\n\
Format the optional arguments under the control of the template string\n\
@var{template} using the same rules as the @code{printf} family of\n\
functions (@pxref{Formatted Output}) and print the resulting message\n\
on the @code{stderr} stream. The message is prefixed by the character\n\
string @samp{error: }.\n\
\n\
Calling @code{error} also sets Octave's internal error state such that\n\
control will return to the top level without evaluating any more\n\
commands. This is useful for aborting from functions or scripts.\n\
\n\
If the error message does not end with a new line character, Octave will\n\
print a traceback of all the function calls leading to the error. For\n\
example, given the following function definitions:\n\
\n\
@example\n\
@group\n\
function f () g (); end\n\
function g () h (); end\n\
function h () nargin == 1 || error (\"nargin != 1\"); end\n\
@end group\n\