How to customize exception message
<pre><code># python 3.5
&gt;&gt;&gt; class MyError(Exception):
...   pass
...
&gt;&gt;&gt; raise MyError('message')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
__main__.MyError: message
</code></pre>

<p>I want the exception to print just <code>message</code> instead of <code>__main__.MyError: message</code>. I tried defininig <code>__str__</code> and <code>__repr__</code> in both <code>MyError</code> itself and in its metaclass, but those had no effect. Where does python interpreter get <code>__main__.MyError</code> from?</p>

<p>Note that I can easily change how instances of <code>MyError</code> are printed, and how <code>MyError</code> itself is printed, but neither has any effect on the exception message:</p>

<pre><code>class MyType(type):
  def __str__(self):
    return '***'

class MyError(Exception, metaclass=MyType):
  def __str__(self):
    return 'xxx'

print(MyError) # ***
print(MyError()) # xxx
raise MyError() # still the same
</code></pre>