How do I implement proper Exception handling in Java?
<p>I am currently writing a simple program in Java in response to a question. The question says :</p>

<blockquote>
  <p>You are fixing a bug where documents (represented as a String) are failing to be converted to proper xml. This problem can occur because either:<br>
  A. Certain characters fail in the xml, or<br>
  B. Documents passed in have a length > 100 characters (they’re small documents)</p>
</blockquote>

<p>It then lists 5 characters that need escaping (e.g. replace '">'" with the escape sequence;). </p>

<p>I've coded the part to replace special characters with escapes, but I'm not sure what to do about the length.</p>

<pre><code>if (length of string &gt; 100) {
    do what?
}
</code></pre>

<p>I was thinking of maybe implementing a try catch statement, but that's used for runtime exceptions correct? (null pointer, etc). In a design standpoint, what would be the best way to avoid this bug while at the same time completing the job of the function?</p>
