title: Re-raise exception with a different type and message, preserving existing information
body: <p>I'm writing a module and want to have a unified exception hierarchy for the exceptions that it can raise (e.g. inheriting from a <code>FooError</code> abstract class for all the <code>foo</code> module's specific exceptions). This allows users of the module to catch those particular exceptions and handle them distinctly, if needed. But many of the exceptions raised from the module are raised because of some other exception; e.g. failing at some task because of an OSError on a file.</p>
  
  <p>What I need is to <strong>“wrap” the exception caught such that it has a different type and message</strong>, so that information is available further up the propagation hierarchy by whatever catches the exception. But I don't want to lose the existing type, message, and stack trace; that's all useful information for someone trying to debug the problem. A top-level exception handler is no good, since I'm trying to decorate the exception before it makes its way further up the propagation stack, and the top-level handler is too late.</p>
  
  <p>This is partly solved by deriving my module <code>foo</code>'s specific exception types from the existing type (e.g. <code>class FooPermissionError(OSError, FooError)</code>), but that doesn't make it any easier to wrap the existing exception instance in a new type, nor modify the message.</p>
  
  <p>Python's <a href="http://www.python.org/dev/peps/pep-3134/" rel="noreferrer">PEP 3134</a> “Exception Chaining and Embedded Tracebacks” discusses a change accepted in Python 3.0 for “chaining” exception objects, to indicate that a new exception was raised during the handling of an existing exception.</p>
  
  <p>What I'm trying to do is related: I need it also working in earlier Python versions, and I need it not for chaining, but only for polymorphism. What is the right way to do this?</p>