|
sharkysoft.com | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.IllegalArgumentException
com.sharkysoft.printf.PrintfTemplateException
Signals malformed printf format.
Details: Printf for Java throws a
PrintfTemplateException
whenever an attempt is made to parse an
invalid format string or apply illegal arguments to a valid format string.
This exception almost always indicates a bug in the
client code.
Example 1: Invalid format string:
float tax_increase = SOME_VALUE; Printf.out ( "taxes raised by %f% this year", new Object[] {new Float(tax_increase)} );When this code is executed, the format string parser interprets the second percent character as the beginning of a second format specifier. But since the following character, 't', does not correspond to a legal printf conversion type, a
PrintfTemplateException
will be thrown. (The correct format string should read "taxes raised by %f%% this year".)
Even if a format string is syntactically correct, a
PrintfTemplateException
can still be thrown if variable widths and
precisions are used and the supplied arguments are invalid.
Example 2: Valid format string with invalid arguments:
int dec_places = -3; Printf.out ( "pi rounded to %d decimal places is %.*f", new PrintfData(3) .add(dec_places) // intended for "%d" .add(dec_places) // intended for "%.*f" .add(Math.PI) );This code throws a
PrintfTemplateException
because the variable precision specified by "%.*f" cannot be set to -3.
For more information on printf formatting, see Printf
.
Printf
,
Serialized FormMethods inherited from class java.lang.Throwable |
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
|
sharkysoft.com | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1997-2004 Sharkysoft (sharkysoft.com). All rights reserved.