Generic method to handle variable string formats?
<p>I have a series of exception messages:</p>

<pre><code>enum myEnum {
    BASIC(1, "An error occurred"),
    WITH_ERRORID(2, "Error id: {0}"),
    DETAILED(3, "Problem in record {0} with index {1}");
};
</code></pre>

<p>I also have a single, reusable authority for logging and throwing a custom exception:</p>

<pre><code>public void throwException (myEnum message) {
    log.addEntry(message);
    throw new CustomException(message);
}
</code></pre>

<p>Calling the method is straight forward:</p>

<pre><code>throwException (myEnum.DETAILED);
</code></pre>

<p>I am now wrestling with the most elegant way to format the strings.  I could add a toString() method to the enum to format the string based on the number of inputs, and change throwException to accept a String instead:</p>

<pre><code>String msg = message.toString(variable);
throwException (msg);

String msg2 = message.toString(variable, otherVariable);
throwException (msg2);

String msg3 = message.toString(variable, otherVariable, nextVariable);
throwException (msg3);
</code></pre>

<p>While this would work, I would like to move the the repeated toString calls to within throwException().  I was considering passing an ArrayList to throwException().  But I would then have to check the size of the list before I format the string:</p>

<pre><code>if (list.size == 1) MessageFormat.format(message, list.get(0));
if (list.size == 2) MessageFormat.format(message, list.get(0), list.get(1));
</code></pre>

<p>Is a better technical or design approach for solving this problem?</p>
