title: How to properly define and process paramerterized error messages in Java?
body: <p><strong>Examples</strong></p>
  
  <p>I have seen .properties files with a convention similar to the following:</p>
  
  <p>Example 1:</p>
  
  <pre><code>error.connection="Could not connect to host {0}, with IP address: {1}"
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>error.connection="Could not connect to host %s, with IP address: %s."
  </code></pre>
  
  <p>(and XML files like the following) Example 3:</p>
  
  <pre><code>&lt;Error id="connection"&gt;Could not connect to host {0}, with IP address {1}&lt;/Error&gt;
  </code></pre>
  
  <p>The error message defined in example 2 could be processed like this: </p>
  
  <pre><code>// Get error.connection value from .properties file and store it in a variable named ERROR_MESSAGE.
  String errorMessage = String.format(ERROR_MESSAGE, hostname, ipAddress);
  </code></pre>
  
  <p>This approach seems unwieldy and dangerous, as it requires the user of the error message to know how many variables the message string requires when when calling <code>String.format</code></p>
  
  <p><strong>Questions</strong></p>
  
  <p>What is the best practice (including available tools) for defining and processing variable error messages? 
  What is this practice called?  </p>