title: How to parse a ValueError in Python without string parsing?
body: <p>I am running a programming and getting an expected ValueError output of:</p>
  
  <p><code>ValueError: {'code': -123, 'message': 'This is the error'}</code></p>
  
  <p>I cannot figure out how to parse this data and just take the code (or message) value. How can I just get the <code>code</code> value of the ValueError?</p>
  
  <p>I have tried the following:</p>
  
  <ul>
  <li><code>e.code</code>
  
  <ul>
  <li><code>AttributeError: 'ValueError' object has no attribute 'code'</code></li>
  </ul></li>
  <li><code>e['code']</code>
  
  <ul>
  <li><code>TypeError: 'ValueError' object is not subscriptable</code></li>
  </ul></li>
  <li><code>json.loads(e)</code>
  
  <ul>
  <li><code>TypeError: the JSON object must be str, bytes or bytearray, not 'ValueError'</code></li>
  </ul></li>
  </ul>
  
  <p>What is the pythonic way of doing this?</p>
  
  <h2>Edit</h2>
  
  <p>The one thing that <em>does</em> work is taking the string index, but I do not want to do this, as I feel it is not very pythonic.</p>