title: Python raising exception where message has carriage return \r control character
body: <p>I am performing serial communications with an electronic device, and the end of a response message is dictated by a carriage return (<code>\r</code>).  If the response is garbled, I raise a custom exception.  I would like my exception message to show the raw response, which may include a carriage return.</p>
  
  <p>I noticed that carriage returns sort of messes up printing/representation of Python's exceptions.</p>
  
  <p>Is there any way to have Python's exceptions use something like <code>repr</code>?</p>
  
  <hr>
  
  <p><strong>Potential Workaround</strong></p>
  
  <p>I could make a custom exception class and override some behavior to replace <code>\r</code> with <code>"CR"</code>, but I am unsure if there is a simpler way.</p>
  
  <p>I am also unsure which dunder methods to use, nor where to find which dunder methods to use.</p>
  
  <hr>
  
  <p><strong>What I Am Seeing</strong></p>
  
  <p>Input:</p>
  
  <pre class="lang-py prettyprint-override"><code>class SerError(Exception):
      """Serial communications error."""
  
  
  some_msg = f"some_serial\rmessage."
  print(f"some_msg = {some_msg}.\nrepr(some_msg) = {repr(some_msg)}.")
  raise SerError(some_msg)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  message..SerError: some_serial
  </code></pre>
  
  <p>You can see Python is interpreting the control character <code>\r</code> by resetting the cursor to the beginning of the line, where it prints the remainder of the message.</p>
  
  <p>I do not like this behavior, as it overwrites my exception message, as opposed to printing the original message.</p>