Sustainable Method to Provide Additional Information in Exceptions?
<p>I'm looking for a way to provide multiple pieces of information for exceptions back to end users.  The obvious solution of extending Exception ends up with text distributed throughput the code, for example</p>

<pre><code>throw new MyException("Bad data", "The data you entered is incorrect", "http://www.example.com/moreinfo/baddata");
</code></pre>

<p>and this quickly becomes unworkable.</p>

<p>I then looked at a catalogue approach but that's too centralized and requires jumping around from one file to another every time an exception is thrown.  I'm now considering a hybrid approach with a static ErrorInfoMap class that contains mappings from a  key to the more detailed information.  Each class then has a static section that contains its own error mappings, so using the class which throws the above exception as an example I'd change it to:</p>

<pre><code>throw new MyException("Bad data");
</code></pre>

<p>and at the bottom of the class there would be something like:</p>

<pre><code>static {
  ErrorInfoMap.put("Bad data", new ErrorInfo("The data you entered is incorrect", "http://www.example.com/moreinfo/baddata"));
  // Information for other exceptions thrown by this class goes here
}
</code></pre>

<p>which allows an exception handler to fetch the additional information if required.  Is this a good way of solving this issue, or is there a better way to handle this?</p>
