Class PrintfTemplateException

  extended byjava.lang.Throwable
      extended byjava.lang.Exception
          extended byjava.lang.RuntimeException
              extended byjava.lang.IllegalArgumentException
                  extended bycom.sharkysoft.printf.PrintfTemplateException
All Implemented Interfaces:

public class PrintfTemplateException
extends java.lang.IllegalArgumentException

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;
( "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;
( "pi rounded to %d decimal places is %.*f",
  new PrintfData(3)
  .add(dec_places) // intended for "%d"
  .add(dec_places) // intended for "%.*f"

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.

See Also:
Printf, Serialized Form

Methods 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

Copyright © 1997-2004 Sharkysoft ( All rights reserved.