Chapter 7
Conditions
Condition Messages
Some condition classes provide a message to communicate the meaning of the condition to the program user.
Condition messages are constructed
using format strings. A format string is a string template into
which values can be inserted to construct a message. The two-character
format directives %d
, %b
,
%o
, %x
, %c
, %s
, and %=
are
replaced by the corresponding element of the associated sequence
of format arguments. Upper and lower case letters are
equivalent in these format directives. The inserted value is formatted according to the
following table:*
Directive |
Argument Type |
Textual Format |
---|---|---|
|
|
decimal number |
|
|
binary number |
|
|
octal number |
|
|
hexadecimal number |
|
|
character (with no quotes) |
|
|
string (with no quotes) |
|
|
condition message (with no quotes) |
|
|
unspecified, but works with any object |
|
none |
literal |
The text printed by the %=
format directive for any given object is
implementation-defined. The behavior when a format argument is not of the type specified in
the table above is implementation-defined. The behavior when too many or too few format
arguments are supplied is implementation-defined.
The two-character sequence %%
does not consume a format argument, but inserts
a %
character.
All other uses of the %
character in a format string are
implementation-defined.
There is no standard way to get the message from a condition (although it can be inserted into another message). Debuggers get the message using implementation-dependent mechanisms. A streams library or other implementation-dependent feature might include a function to get the message from a condition. However, in some implementations, the message might only exist in the debugger, not in the program runtime.
There is no standard way for a user-defined condition class to supply a message. Individual implementations and libraries can specify such a mechanism that is appropriate to their needs.
* These format directives are
designed for compatibility with C's printf
, with some omissions and with the
addition of %=
.