Java Reference
In-Depth Information
tained from its
out
method (see
Section 22.1.8
on page
631
).
The
flags
,
width
, and
precision
arguments contain the flags,
width, and precision values that were used in the string con-
version format specifier. If no width or precision was given,
then 1 is passed. The flags are encoded as a bit mask from
the constants of the
FormattableFlags
class. Only two flags are
supported:
LEFT_JUSTIFY
, which indicates the flag for left-jus-
tification, and
ALTERNATE
, which indicates the
#
flag. Each
For-
mattable
class is free to define what
ALTERNATE
means.
Additionally, the flag value encodes whether the conversion indicator
was lowercase or uppercase using the
FormattableFlags.UPPERCASE
con-
stant. You can test whether a flag is set by
AND
ing the
flags
value with
the desired constant and seeing if the result is non-zero.
By implementing
Formattable
a class can provide greater flexibility in
how it represents itself textually, compared to the fixed output of the
toString
method. For example, it can use a long or short form, depend-
ing on the width and precision that were supplied; or it can adapt itself
22.1.7. Format Exceptions
If any errors occur while processing a format string with a given set of
arguments, an exception that is a subclass of
IllegalFormatException
will
be thrown. The types of exception you can encounter are
•
DuplicateFormatFlagsException
A flag was used more than once.
•
FormatFlagsConversionMismatchException
A flag was incompatible
with the conversion.
•
IllegalFormatCodePointException
An integer value was passed that
was not a valid Unicode codepoint.
•
IllegalFormatConversionException
The argument was the wrong
type for the conversion.