How to avoid duplicating complicated catch blocks
<p>I have this code:</p>

<pre><code>try {
    do_stuff();
    return do_more_stuff();
} catch (UnsupportedEncodingException e) {
    throw CustomException.programmer_error(e);
} catch (ProtocolException e) {
    throw CustomException.programmer_error(e);
} catch (MalformedURLException e) {
    throw CustomException.programmer_error(e);
} catch (SocketTimeoutException e) {
    throw new CustomException(e);
} catch (IOException e) {
    throw CustomException.unexpected_error(e);
}
</code></pre>

<p>I now need to have all those catch blocks in another similar function. What is the best way to avoid duplication here?</p>

<p>Note that the code inside the two try blocks is not very similar.</p>

<p>Also I can't really put the set of catches higher up.</p>

<p>Note, I'd prefer to avoid:</p>

<pre><code>try {
    do_stuff();
    return do_more_stuff();
} catch (Exception e) {
    handle_exception_via_rtti(e);
}
</code></pre>
