forked from cplusplus/draft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagnostics.tex
2578 lines (2143 loc) · 73.9 KB
/
diagnostics.tex
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
%!TEX root = std.tex
\rSec0[diagnostics]{Diagnostics library}
\rSec1[diagnostics.general]{General}
\pnum
This Clause describes components that \Cpp{} programs may use to detect and
report error conditions.
\pnum
The following subclauses describe components for
reporting several kinds of exceptional conditions,
documenting program assertions,
obtaining stacktraces, and
a global variable for error number codes,
as summarized in \tref{diagnostics.summary}.
\begin{libsumtab}{Diagnostics library summary}{diagnostics.summary}
\ref{std.exceptions} & Exception classes & \tcode{<stdexcept>} \\ \rowsep
\ref{assertions} & Assertions & \tcode{<cassert>} \\ \rowsep
\ref{errno} & Error numbers & \tcode{<cerrno>} \\ \rowsep
\ref{syserr} & System error support & \tcode{<system_error>} \\ \rowsep
\ref{stacktrace} & Stacktrace & \tcode{<stacktrace>} \\ \rowsep
\ref{debugging} & Debugging & \tcode{<debugging>} \\
\end{libsumtab}
\rSec1[std.exceptions]{Exception classes}
\rSec2[std.exceptions.general]{General}
\pnum
The \Cpp{} standard library provides classes to be used to report certain errors\iref{res.on.exception.handling} in
\Cpp{} programs.
In the error model reflected in these classes, errors are divided into two
broad categories:
\term{logic}
errors and
\term{runtime}
errors.
\pnum
The distinguishing characteristic of logic errors is that they are due to errors
in the internal logic of the program.
In theory, they are preventable.
\pnum
By contrast, runtime errors are due to events beyond the scope of the program.
They cannot be easily predicted in advance.
The header \libheaderdef{stdexcept}
defines several types of predefined exceptions for reporting errors in a \Cpp{} program.
These exceptions are related by inheritance.
\rSec2[stdexcept.syn]{Header \tcode{<stdexcept>} synopsis}
\indexlibraryglobal{logic_error}%
\indexlibraryglobal{domain_error}%
\indexlibraryglobal{invalid_argument}%
\indexlibraryglobal{length_error}%
\indexlibraryglobal{out_of_range}%
\indexlibraryglobal{runtime_error}%
\indexlibraryglobal{range_error}%
\indexlibraryglobal{overflow_error}%
\indexlibraryglobal{underflow_error}%
\begin{codeblock}
namespace std {
class logic_error;
class domain_error;
class invalid_argument;
class length_error;
class out_of_range;
class runtime_error;
class range_error;
class overflow_error;
class underflow_error;
}
\end{codeblock}
\rSec2[logic.error]{Class \tcode{logic_error}}
\indexlibraryglobal{logic_error}%
\begin{codeblock}
namespace std {
class logic_error : public exception {
public:
explicit logic_error(const string& what_arg);
explicit logic_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{logic_error}
defines the type of objects thrown as
exceptions to report errors presumably detectable before
the program executes, such as violations of logical preconditions or class
invariants.
\indexlibraryctor{logic_error}%
\begin{itemdecl}
logic_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{logic_error}%
\begin{itemdecl}
logic_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[domain.error]{Class \tcode{domain_error}}
\indexlibraryglobal{domain_error}%
\begin{codeblock}
namespace std {
class domain_error : public logic_error {
public:
explicit domain_error(const string& what_arg);
explicit domain_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{domain_error}
defines the type of objects thrown as
exceptions by the implementation to report domain errors.
\indexlibraryctor{domain_error}%
\begin{itemdecl}
domain_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{domain_error}%
\begin{itemdecl}
domain_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[invalid.argument]{Class \tcode{invalid_argument}}
\indexlibraryglobal{invalid_argument}%
\begin{codeblock}
namespace std {
class invalid_argument : public logic_error {
public:
explicit invalid_argument(const string& what_arg);
explicit invalid_argument(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{invalid_argument}
defines the type of objects thrown as exceptions to report an invalid argument.
\indexlibraryctor{invalid_argument}%
\begin{itemdecl}
invalid_argument(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{invalid_argument}%
\begin{itemdecl}
invalid_argument(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[length.error]{Class \tcode{length_error}}
\indexlibraryglobal{length_error}%
\begin{codeblock}
namespace std {
class length_error : public logic_error {
public:
explicit length_error(const string& what_arg);
explicit length_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{length_error}
defines the type of objects thrown as exceptions
to report an attempt to produce
an object whose length exceeds its maximum allowable size.
\indexlibraryctor{length_error}%
\begin{itemdecl}
length_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{length_error}%
\begin{itemdecl}
length_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[out.of.range]{Class \tcode{out_of_range}}
\indexlibraryglobal{out_of_range}%
\begin{codeblock}
namespace std {
class out_of_range : public logic_error {
public:
explicit out_of_range(const string& what_arg);
explicit out_of_range(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{out_of_range}
defines the type of objects thrown as exceptions to report an
argument value not in its expected range.
\indextext{argument}
\indexlibraryctor{out_of_range}%
\begin{itemdecl}
out_of_range(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{out_of_range}%
\begin{itemdecl}
out_of_range(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[runtime.error]{Class \tcode{runtime_error}}
\indexlibraryglobal{runtime_error}%
\begin{codeblock}
namespace std {
class runtime_error : public exception {
public:
explicit runtime_error(const string& what_arg);
explicit runtime_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{runtime_error}
defines the type of objects thrown as exceptions to report errors presumably detectable only
when the program executes.
\indexlibraryctor{runtime_error}%
\begin{itemdecl}
runtime_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{runtime_error}%
\begin{itemdecl}
runtime_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[range.error]{Class \tcode{range_error}}
\indexlibraryglobal{range_error}%
\begin{codeblock}
namespace std {
class range_error : public runtime_error {
public:
explicit range_error(const string& what_arg);
explicit range_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{range_error}
defines the type of objects thrown as exceptions to report range errors
in internal computations.
\indexlibraryctor{range_error}%
\begin{itemdecl}
range_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{range_error}%
\begin{itemdecl}
range_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[overflow.error]{Class \tcode{overflow_error}}
\indexlibraryglobal{overflow_error}%
\begin{codeblock}
namespace std {
class overflow_error : public runtime_error {
public:
explicit overflow_error(const string& what_arg);
explicit overflow_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{overflow_error}
defines the type of objects thrown as exceptions to report an arithmetic overflow error.
\indexlibraryctor{overflow_error}%
\begin{itemdecl}
overflow_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{overflow_error}%
\begin{itemdecl}
overflow_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec2[underflow.error]{Class \tcode{underflow_error}}
\indexlibraryglobal{underflow_error}%
\begin{codeblock}
namespace std {
class underflow_error : public runtime_error {
public:
explicit underflow_error(const string& what_arg);
explicit underflow_error(const char* what_arg);
};
}
\end{codeblock}
\pnum
The class
\tcode{underflow_error}
defines the type of objects thrown as exceptions to report an arithmetic underflow error.
\indexlibraryctor{underflow_error}%
\begin{itemdecl}
underflow_error(const string& what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg.c_str()) == 0}.
\end{itemdescr}
\indexlibraryctor{underflow_error}%
\begin{itemdecl}
underflow_error(const char* what_arg);
\end{itemdecl}
\begin{itemdescr}
\pnum
\ensures
\tcode{strcmp(what(), what_arg) == 0}.
\end{itemdescr}
\rSec1[assertions]{Assertions}
\rSec2[assertions.general]{General}
\pnum
The header \libheaderdef{cassert}
provides a macro for documenting \Cpp{} program assertions and a mechanism
for disabling the assertion checks through defining the macro \tcode{NDEBUG}.
\rSec2[cassert.syn]{Header \tcode{<cassert>} synopsis}
\indexlibraryglobal{assert}%
\begin{codeblock}
#define assert(...) @\seebelow@
\end{codeblock}
\rSec2[assertions.assert]{The \tcode{assert} macro}
\pnum
If \tcode{NDEBUG} is defined as a macro name
at the point in the source file where \tcode{<cassert>} is included,
the \tcode{assert} macro is defined as
\begin{codeblock}
#define assert(...) ((void)0)
\end{codeblock}
\pnum
Otherwise, the \tcode{assert} macro puts a diagnostic test into programs;
it expands to an expression of type \keyword{void} which
has the following effects:
\begin{itemize}
\item
\mname{VA_ARGS} is evaluated and contextually converted to \tcode{bool}.
\item
If the evaluation yields \tcode{true} there are no further effects.
\item
Otherwise, the \tcode{assert} macro's expression
creates a diagnostic on the standard error stream in an
\impldef{format of diagnostic created by \tcode{assert} macro's expression}
format and calls \tcode{abort()}.
The diagnostic contains \tcode{\#}\mname{VA_ARGS} and
information on
the name of the source file,
the source line number, and
the name of the enclosing function
(such as provided by \tcode{source_location::current()}).
\end{itemize}
\pnum
If \mname{VA_ARGS} does not expand to
an \grammarterm{assignment-expression},
the program is ill-formed.
\pnum
The macro \tcode{assert} is redefined according to
the current state of \tcode{NDEBUG} each time that
\tcode{<cassert>} is included.
\pnum
An expression \tcode{assert(E)}
is a constant subexpression\iref{defns.const.subexpr}, if
\begin{itemize}
\item
\tcode{NDEBUG} is defined at the point where \tcode{assert}
is last defined or redefined, or
\item
\tcode{E} contextually converted to \tcode{bool}\iref{conv}
is a constant subexpression that evaluates to the value \tcode{true}.
\end{itemize}
\rSec1[errno]{Error numbers}
\rSec2[errno.general]{General}
\pnum
The contents of the header \libheaderdef{cerrno} are the same as the POSIX header
\libheader{errno.h}, except that \tcode{errno} shall be defined as a macro.
\begin{note}
The intent is to remain in close alignment with the POSIX standard.
\end{note}
A separate \tcode{errno} value is provided for each thread.
\rSec2[cerrno.syn]{Header \tcode{<cerrno>} synopsis}
\indexlibraryglobal{errno}%
\indexlibraryglobal{E2BIG}%
\indexlibraryglobal{EACCES}%
\indexlibraryglobal{EADDRINUSE}%
\indexlibraryglobal{EADDRNOTAVAIL}%
\indexlibraryglobal{EAFNOSUPPORT}%
\indexlibraryglobal{EAGAIN}%
\indexlibraryglobal{EALREADY}%
\indexlibraryglobal{EBADF}%
\indexlibraryglobal{EBADMSG}%
\indexlibraryglobal{EBUSY}%
\indexlibraryglobal{ECANCELED}%
\indexlibraryglobal{ECHILD}%
\indexlibraryglobal{ECONNABORTED}%
\indexlibraryglobal{ECONNREFUSED}%
\indexlibraryglobal{ECONNRESET}%
\indexlibraryglobal{EDEADLK}%
\indexlibraryglobal{EDESTADDRREQ}%
\indexlibraryglobal{EDOM}%
\indexlibraryglobal{EEXIST}%
\indexlibraryglobal{EFAULT}%
\indexlibraryglobal{EFBIG}%
\indexlibraryglobal{EHOSTUNREACH}%
\indexlibraryglobal{EIDRM}%
\indexlibraryglobal{EILSEQ}%
\indexlibraryglobal{EINPROGRESS}%
\indexlibraryglobal{EINTR}%
\indexlibraryglobal{EINVAL}%
\indexlibraryglobal{EIO}%
\indexlibraryglobal{EISCONN}%
\indexlibraryglobal{EISDIR}%
\indexlibraryglobal{ELOOP}%
\indexlibraryglobal{EMFILE}%
\indexlibraryglobal{EMLINK}%
\indexlibraryglobal{EMSGSIZE}%
\indexlibraryglobal{ENAMETOOLONG}%
\indexlibraryglobal{ENETDOWN}%
\indexlibraryglobal{ENETRESET}%
\indexlibraryglobal{ENETUNREACH}%
\indexlibraryglobal{ENFILE}%
\indexlibraryglobal{ENOBUFS}%
\indexlibraryglobal{ENODEV}%
\indexlibraryglobal{ENOENT}%
\indexlibraryglobal{ENOEXEC}%
\indexlibraryglobal{ENOLCK}%
\indexlibraryglobal{ENOLINK}%
\indexlibraryglobal{ENOMEM}%
\indexlibraryglobal{ENOMSG}%
\indexlibraryglobal{ENOPROTOOPT}%
\indexlibraryglobal{ENOSPC}%
\indexlibraryglobal{ENOSYS}%
\indexlibraryglobal{ENOTCONN}%
\indexlibraryglobal{ENOTDIR}%
\indexlibraryglobal{ENOTEMPTY}%
\indexlibraryglobal{ENOTRECOVERABLE}%
\indexlibraryglobal{ENOTSOCK}%
\indexlibraryglobal{ENOTSUP}%
\indexlibraryglobal{ENOTTY}%
\indexlibraryglobal{ENXIO}%
\indexlibraryglobal{EOPNOTSUPP}%
\indexlibraryglobal{EOVERFLOW}%
\indexlibraryglobal{EOWNERDEAD}%
\indexlibraryglobal{EPERM}%
\indexlibraryglobal{EPIPE}%
\indexlibraryglobal{EPROTO}%
\indexlibraryglobal{EPROTONOSUPPORT}%
\indexlibraryglobal{EPROTOTYPE}%
\indexlibraryglobal{ERANGE}%
\indexlibraryglobal{EROFS}%
\indexlibraryglobal{ESPIPE}%
\indexlibraryglobal{ESRCH}%
\indexlibraryglobal{ETIMEDOUT}%
\indexlibraryglobal{ETXTBSY}%
\indexlibraryglobal{EWOULDBLOCK}%
\indexlibraryglobal{EXDEV}%
\begin{codeblock}
#define errno @\seebelow@
#define E2BIG @\seebelow@ // freestanding
#define EACCES @\seebelow@ // freestanding
#define EADDRINUSE @\seebelow@ // freestanding
#define EADDRNOTAVAIL @\seebelow@ // freestanding
#define EAFNOSUPPORT @\seebelow@ // freestanding
#define EAGAIN @\seebelow@ // freestanding
#define EALREADY @\seebelow@ // freestanding
#define EBADF @\seebelow@ // freestanding
#define EBADMSG @\seebelow@ // freestanding
#define EBUSY @\seebelow@ // freestanding
#define ECANCELED @\seebelow@ // freestanding
#define ECHILD @\seebelow@ // freestanding
#define ECONNABORTED @\seebelow@ // freestanding
#define ECONNREFUSED @\seebelow@ // freestanding
#define ECONNRESET @\seebelow@ // freestanding
#define EDEADLK @\seebelow@ // freestanding
#define EDESTADDRREQ @\seebelow@ // freestanding
#define EDOM @\seebelow@ // freestanding
#define EEXIST @\seebelow@ // freestanding
#define EFAULT @\seebelow@ // freestanding
#define EFBIG @\seebelow@ // freestanding
#define EHOSTUNREACH @\seebelow@ // freestanding
#define EIDRM @\seebelow@ // freestanding
#define EILSEQ @\seebelow@ // freestanding
#define EINPROGRESS @\seebelow@ // freestanding
#define EINTR @\seebelow@ // freestanding
#define EINVAL @\seebelow@ // freestanding
#define EIO @\seebelow@ // freestanding
#define EISCONN @\seebelow@ // freestanding
#define EISDIR @\seebelow@ // freestanding
#define ELOOP @\seebelow@ // freestanding
#define EMFILE @\seebelow@ // freestanding
#define EMLINK @\seebelow@ // freestanding
#define EMSGSIZE @\seebelow@ // freestanding
#define ENAMETOOLONG @\seebelow@ // freestanding
#define ENETDOWN @\seebelow@ // freestanding
#define ENETRESET @\seebelow@ // freestanding
#define ENETUNREACH @\seebelow@ // freestanding
#define ENFILE @\seebelow@ // freestanding
#define ENOBUFS @\seebelow@ // freestanding
#define ENODEV @\seebelow@ // freestanding
#define ENOENT @\seebelow@ // freestanding
#define ENOEXEC @\seebelow@ // freestanding
#define ENOLCK @\seebelow@ // freestanding
#define ENOLINK @\seebelow@ // freestanding
#define ENOMEM @\seebelow@ // freestanding
#define ENOMSG @\seebelow@ // freestanding
#define ENOPROTOOPT @\seebelow@ // freestanding
#define ENOSPC @\seebelow@ // freestanding
#define ENOSYS @\seebelow@ // freestanding
#define ENOTCONN @\seebelow@ // freestanding
#define ENOTDIR @\seebelow@ // freestanding
#define ENOTEMPTY @\seebelow@ // freestanding
#define ENOTRECOVERABLE @\seebelow@ // freestanding
#define ENOTSOCK @\seebelow@ // freestanding
#define ENOTSUP @\seebelow@ // freestanding
#define ENOTTY @\seebelow@ // freestanding
#define ENXIO @\seebelow@ // freestanding
#define EOPNOTSUPP @\seebelow@ // freestanding
#define EOVERFLOW @\seebelow@ // freestanding
#define EOWNERDEAD @\seebelow@ // freestanding
#define EPERM @\seebelow@ // freestanding
#define EPIPE @\seebelow@ // freestanding
#define EPROTO @\seebelow@ // freestanding
#define EPROTONOSUPPORT @\seebelow@ // freestanding
#define EPROTOTYPE @\seebelow@ // freestanding
#define ERANGE @\seebelow@ // freestanding
#define EROFS @\seebelow@ // freestanding
#define ESPIPE @\seebelow@ // freestanding
#define ESRCH @\seebelow@ // freestanding
#define ETIMEDOUT @\seebelow@ // freestanding
#define ETXTBSY @\seebelow@ // freestanding
#define EWOULDBLOCK @\seebelow@ // freestanding
#define EXDEV @\seebelow@ // freestanding
\end{codeblock}
\pnum
The meaning of the macros in this header is defined by the POSIX standard.
\xrefc{7.5}
\rSec1[syserr]{System error support}
\rSec2[syserr.general]{General}
\pnum
Subclause \ref{syserr} describes components that the standard library and
\Cpp{} programs may use to report error conditions originating from
the operating system or other low-level application program interfaces.
\pnum
Components described in \ref{syserr} do not change the value of
\tcode{errno}\iref{errno}.
\recommended
Implementations should leave the error states provided by other
libraries unchanged.
\rSec2[system.error.syn]{Header \tcode{<system_error>} synopsis}
\indexheader{system_error}%
\indexlibraryglobal{error_category}%
\indexlibraryglobal{error_code}%
\indexlibraryglobal{error_condition}%
\indexlibraryglobal{system_error}%
\begin{codeblock}
#include <compare> // see \ref{compare.syn}
namespace std {
class error_category;
const error_category& generic_category() noexcept;
const error_category& system_category() noexcept;
class error_code;
class error_condition;
class system_error;
template<class T>
struct @\libglobal{is_error_code_enum}@ : public false_type {};
template<class T>
struct @\libglobal{is_error_condition_enum}@ : public false_type {};
enum class @\libglobal{errc}@ { // freestanding
address_family_not_supported, // \tcode{EAFNOSUPPORT}
address_in_use, // \tcode{EADDRINUSE}
address_not_available, // \tcode{EADDRNOTAVAIL}
already_connected, // \tcode{EISCONN}
argument_list_too_long, // \tcode{E2BIG}
argument_out_of_domain, // \tcode{EDOM}
bad_address, // \tcode{EFAULT}
bad_file_descriptor, // \tcode{EBADF}
bad_message, // \tcode{EBADMSG}
broken_pipe, // \tcode{EPIPE}
connection_aborted, // \tcode{ECONNABORTED}
connection_already_in_progress, // \tcode{EALREADY}
connection_refused, // \tcode{ECONNREFUSED}
connection_reset, // \tcode{ECONNRESET}
cross_device_link, // \tcode{EXDEV}
destination_address_required, // \tcode{EDESTADDRREQ}
device_or_resource_busy, // \tcode{EBUSY}
directory_not_empty, // \tcode{ENOTEMPTY}
executable_format_error, // \tcode{ENOEXEC}
file_exists, // \tcode{EEXIST}
file_too_large, // \tcode{EFBIG}
filename_too_long, // \tcode{ENAMETOOLONG}
function_not_supported, // \tcode{ENOSYS}
host_unreachable, // \tcode{EHOSTUNREACH}
identifier_removed, // \tcode{EIDRM}
illegal_byte_sequence, // \tcode{EILSEQ}
inappropriate_io_control_operation, // \tcode{ENOTTY}
interrupted, // \tcode{EINTR}
invalid_argument, // \tcode{EINVAL}
invalid_seek, // \tcode{ESPIPE}
io_error, // \tcode{EIO}
is_a_directory, // \tcode{EISDIR}
message_size, // \tcode{EMSGSIZE}
network_down, // \tcode{ENETDOWN}
network_reset, // \tcode{ENETRESET}
network_unreachable, // \tcode{ENETUNREACH}
no_buffer_space, // \tcode{ENOBUFS}
no_child_process, // \tcode{ECHILD}
no_link, // \tcode{ENOLINK}
no_lock_available, // \tcode{ENOLCK}
no_message, // \tcode{ENOMSG}
no_protocol_option, // \tcode{ENOPROTOOPT}
no_space_on_device, // \tcode{ENOSPC}
no_such_device_or_address, // \tcode{ENXIO}
no_such_device, // \tcode{ENODEV}
no_such_file_or_directory, // \tcode{ENOENT}
no_such_process, // \tcode{ESRCH}
not_a_directory, // \tcode{ENOTDIR}
not_a_socket, // \tcode{ENOTSOCK}
not_connected, // \tcode{ENOTCONN}
not_enough_memory, // \tcode{ENOMEM}
not_supported, // \tcode{ENOTSUP}
operation_canceled, // \tcode{ECANCELED}
operation_in_progress, // \tcode{EINPROGRESS}
operation_not_permitted, // \tcode{EPERM}
operation_not_supported, // \tcode{EOPNOTSUPP}
operation_would_block, // \tcode{EWOULDBLOCK}
owner_dead, // \tcode{EOWNERDEAD}
permission_denied, // \tcode{EACCES}
protocol_error, // \tcode{EPROTO}
protocol_not_supported, // \tcode{EPROTONOSUPPORT}
read_only_file_system, // \tcode{EROFS}
resource_deadlock_would_occur, // \tcode{EDEADLK}
resource_unavailable_try_again, // \tcode{EAGAIN}
result_out_of_range, // \tcode{ERANGE}
state_not_recoverable, // \tcode{ENOTRECOVERABLE}
text_file_busy, // \tcode{ETXTBSY}
timed_out, // \tcode{ETIMEDOUT}
too_many_files_open_in_system, // \tcode{ENFILE}
too_many_files_open, // \tcode{EMFILE}
too_many_links, // \tcode{EMLINK}
too_many_symbolic_link_levels, // \tcode{ELOOP}
value_too_large, // \tcode{EOVERFLOW}
wrong_protocol_type, // \tcode{EPROTOTYPE}
};
template<> struct is_error_condition_enum<errc> : true_type {};
// \ref{syserr.errcode.nonmembers}, non-member functions
error_code make_error_code(errc e) noexcept;
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
// \ref{syserr.errcondition.nonmembers}, non-member functions
error_condition make_error_condition(errc e) noexcept;
// \ref{syserr.compare}, comparison operator functions
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept;
// \ref{syserr.hash}, hash support
template<class T> struct hash;
template<> struct hash<error_code>;
template<> struct hash<error_condition>;
// \ref{syserr}, system error support
template<class T>
constexpr bool @\libglobal{is_error_code_enum_v}@ = is_error_code_enum<T>::value;
template<class T>
constexpr bool is_error_condition_enum_v = is_error_condition_enum<T>::value;
}
\end{codeblock}
\pnum
The value of each \tcode{enum errc} enumerator is the same as
the value of the \libheader{cerrno} macro shown in the above synopsis.
Whether or not the \libheader{system_error} implementation
exposes the \libheader{cerrno} macros is unspecified.
\pnum
The \tcode{is_error_code_enum} and \tcode{is_error_condition_enum} templates may be
specialized for program-defined types to indicate that such types are eligible
for \tcode{class error_code} and \tcode{class error_condition} implicit
conversions, respectively.
\rSec2[syserr.errcat]{Class \tcode{error_category}}
\rSec3[syserr.errcat.overview]{Overview}
\pnum
The class \tcode{error_category} serves as a base class for types used
to identify the source and encoding of a particular category of error code.
Classes may be derived from \tcode{error_category} to support
categories of errors in addition to those defined in this document.
Such classes shall behave as specified in subclause~\ref{syserr.errcat}.
\begin{note}
\tcode{error_category} objects are
passed by reference, and two such objects
are equal if they have the same address.
If there is more than a single object of a custom \tcode{error_category} type,
such equality comparisons can evaluate to \tcode{false}
even for objects holding the same value.
\end{note}
\indexlibraryglobal{error_category}%
\indexlibraryctor{error_category}%
\indexlibrarydtor{error_category}%
\indexlibraryglobal{generic_category}%
\indexlibraryglobal{system_category}%
\begin{codeblock}
namespace std {
class error_category {
public:
constexpr error_category() noexcept;
virtual ~error_category();
error_category(const error_category&) = delete;
error_category& operator=(const error_category&) = delete;
virtual const char* name() const noexcept = 0;
virtual error_condition default_error_condition(int ev) const noexcept;
virtual bool equivalent(int code, const error_condition& condition) const noexcept;
virtual bool equivalent(const error_code& code, int condition) const noexcept;
virtual string message(int ev) const = 0;
bool operator==(const error_category& rhs) const noexcept;
strong_ordering operator<=>(const error_category& rhs) const noexcept;
};
const error_category& generic_category() noexcept;
const error_category& system_category() noexcept;
}
\end{codeblock}
\rSec3[syserr.errcat.virtuals]{Virtual members}
\indexlibrarymember{name}{error_category}%
\begin{itemdecl}
virtual const char* name() const noexcept = 0;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
A string naming the error category.
\end{itemdescr}
\indexlibrarymember{default_error_condition}{error_category}%
\begin{itemdecl}
virtual error_condition default_error_condition(int ev) const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
\tcode{error_condition(ev, *this)}.
\end{itemdescr}
\indexlibrarymember{equivalent}{error_category}%
\begin{itemdecl}
virtual bool equivalent(int code, const error_condition& condition) const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
\tcode{default_error_condition(code) == condition}.
\end{itemdescr}
\indexlibrarymember{equivalent}{error_category}%
\begin{itemdecl}
virtual bool equivalent(const error_code& code, int condition) const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
\tcode{*this == code.category() \&\& code.value() == condition}.
\end{itemdescr}
\indexlibrarymember{message}{error_category}%
\begin{itemdecl}
virtual string message(int ev) const = 0;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
A string that describes the error condition denoted by \tcode{ev}.
\end{itemdescr}
\rSec3[syserr.errcat.nonvirtuals]{Non-virtual members}
\indexlibrarymember{operator==}{error_category}%
\begin{itemdecl}
bool operator==(const error_category& rhs) const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
\tcode{this == \&rhs}.
\end{itemdescr}
\indexlibrarymember{operator<=>}{error_category}%
\begin{itemdecl}
strong_ordering operator<=>(const error_category& rhs) const noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
\tcode{compare_three_way()(this, \&rhs)}.
\begin{note}
\tcode{compare_three_way}\iref{comparisons.three.way} provides a total ordering for pointers.
\end{note}
\end{itemdescr}
\rSec3[syserr.errcat.derived]{Program-defined classes derived from \tcode{error_category}}
\indexlibrarymember{name}{error_category}%
\begin{itemdecl}
virtual const char* name() const noexcept = 0;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
A string naming the error category.
\end{itemdescr}
\indexlibrarymember{default_error_condition}{error_category}%