title: Handling exception in Tkinter
body: <pre><code>class Application(object):
      def __init__(self, master):
          self.master = master
          Tk.report_callback_exception = self.show_error
  
      def show_error(self, *args):
          err = traceback.format_exception(*args)
          messagebox.showerror('Title', f"{err[-1]}")
  </code></pre>
  
  <p>When an exception is raised I will have something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/opzU3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/opzU3.png" alt="ZeroDivisionError"></a></p>
  
  <p>If a create a simple Class Exception from Exception to easily pass description:</p>
  
  <pre><code>class Pingu_Exception(Exception):
      pass
  </code></pre>
  
  <p>if i except a ZeroDivisionError and Raise my error(Pingu_Exception) from an imported python file
  I can easily catch it </p>
  
  <pre><code>try:
          x = 4 / 0
  except ZeroDivisionError:
          raise Pingu_Exception("Description")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ibMyq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ibMyq.png" alt="Pingu_Exception"></a></p>
  
  <p>The problem is when I try to catch imported Exception.
  For example:</p>
  
  <pre><code>from requests.exceptions import ReadTimeout
  
  
  class Woocommerce_api(object):
      def __init__(self):
          self.orders_endpoint = "orders/"
          self.customers_endpoint = "customers/"
          self.products_endpoint = "products/"
  
      def __api_json(self, endpoint):
  
          try:
              wcapi = API(
                  url="https://www.xxxx.it",
                  consumer_key=self.consumer_key,
                  consumer_secret=self.consumer_secret,
                  wp_api=True,
                  version="wc/v1",
                  query_string_auth=True,
                  timeout=3
              )
              return wcapi
  
          except requests.exceptions.ReadTimeout:
              raise Pingu_Exception('"Timeout error\nIl server non risponde\nRiprova nuovamente')
  </code></pre>
  
  <p>This is what I catch:</p>
  
  <p><a href="https://i.stack.imgur.com/jOOTV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jOOTV.png" alt="request exception"></a></p>
  
  <p>but if a try to raise an requests.exceptions.ReadTimeout, in his same function, it will work:</p>
  
  <pre><code>def __api_json(self, endpoint):
      try:
          raise requests.exceptions.ReadTimeout
  
          wcapi = API(
              url="https://www.slow-sud.it",
              consumer_key=self.consumer_key,
              consumer_secret=self.consumer_secret,
              wp_api=True,
              version="wc/v1",
              query_string_auth=True,
              timeout=3
          )
          return wcapi
  except requests.exceptions.ReadTimeout:
          raise Pingu_Exception('"Timeout error\nIl server non risponde\nRiprova nuovamente')
          return False
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ariI9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ariI9.png" alt="enter image description here"></a></p>