title: .net - How to change exception message of Exception object?
body: <p>How can i change the <code>Message</code> of an Exception object in C#?</p>
  
  <h2>Bonus Chatter</h2>
  
  <p>The <code>Message</code> property of <code>Exception</code> is <em>read-only</em>:</p>
  
  <pre><code>public virtual string Message { get; }
  </code></pre>
  
  <h2>Additional Reading</h2>
  
  <p>The same question, in PHP, was answered, <em>"You can't"</em>, but gave a workaround:</p>
  
  <blockquote>
    <p>You can however determine it's class name and code, and throw a new one, of the same class, with same code, but with different message.</p>
  </blockquote>
  
  <p>How can i determine an exception's class name, and throw a new one of the same class, but with a different message, in C#?</p>
  
  <p>e.g.:</p>
  
  <pre><code>catch (Exception e)
  {
     Exception e2 = Activator.CreateInstance(e.GetType());
     throw e2;
  }
  </code></pre>
  
  <p>doesn't work because the <code>Message</code> property of an exception is read-only and .NET. See original question.</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>i tried catching each type of exception i expect:</p>
  
  <pre><code>try
  {
      reader.Read();
  }
  catch (OleDbException e)
  {
     throw new OleDbException(e, sql);
  }
  catch (SqlException e)
  {
     throw new SqlException (e, sql);
  }
  catch (IBM.DbException e)
  {
     throw new IBM.DbException(e, sql);
  }
  catch (OdbcException e)
  {
     throw new OdbcException (e, sql);
  }
  catch (OracleException e)
  {
     throw new OracleException (e, sql);
  }
  </code></pre>
  
  <p>Except that now my code forces a dependency on assemblies that won't be present in every solution.</p>
  
  <p>Also, now the exception seems to come from my code, rather than the line that threw it; i lose the exception's location information</p>