title: Custom python error class is always raising error
body: <p>I hope you can help me with some doubts about exception classes in python.<br />
  I don't want to use Exception class in my try/except statements so I have created a custom class:</p>
  <pre class="lang-py prettyprint-override"><code>class MyCustomError (Exception): 
     pass
  </code></pre>
  <p>In my code, I want to control the exception so I use try/except sentence:</p>
  <pre class="lang-py prettyprint-override"><code>def my_function():
    try:
      my code.....
    except MyCustomError as e:
      print(&quot;There is an error in my_function()&quot;)
  </code></pre>
  <p>If I use <code>MyCustomError </code> to control the exception, it is raised. But if I use generic class <code>Exception</code>, exception is not raised and only print message is given.</p>
  <p>How can I control the exceptions using a custom class as it is done using Exception class?</p>
  <h3>UPDATE</h3>
  <p>The code I use</p>
  <pre class="lang-py prettyprint-override"><code>class DatabaseErrorException (Exception): 
     pass
  
  
  class DbConnector:
    def __init__(self, parameters):
      self.params=parameters
      self.connection=None
  
    def connect():
      self.connection = psycopg2.connect(**self.parameters)
      return self.connection
  
    def insert_table(self, query):
      try:
        with self.connection.cursor() as cursor:
          cursor.execute(query)
          rowcount = cursor.rowcount
          self.connection.commit()
        return True
      except DatabaseErrorException as ex:
        print(&quot;Error to insert table&quot;)
        return False
  </code></pre>
  <p>The error is the exception if try fails. For example, if table is wrong:</p>
  <pre class="lang-py prettyprint-override"><code>params = {
          'db_host': 'host',
          'db_user': 'postgres_user',
          'db_pass': 'pass',
          'db_port': '5432',
          'db_database': 'test'}
  
  dbcon_obj = DbConnector(params)
  con = dbcon_obj.connect()
  con.insert_table(query=insert_query)
  </code></pre>
  <p>The error is:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;test_postgrest.py&quot;, line 51, in &lt;module&gt;
      count = con.insert_table(table1, query)
    insert_table
      cursor.executemany(query)
  psycopg2.errors.UndefinedTable: no existe la relación «accxounts»
  LINE 1: INSERT INTO accxounts (user_id, username, password, email) V...
  </code></pre>
  <p>But if I implement <code>insert_table</code> with Exception class:</p>
  <pre class="lang-py prettyprint-override"><code>  def insert_table(self, query):
      try:
        with self.connection.cursor() as cursor:
          cursor.execute(query)
          rowcount = cursor.rowcount
          self.connection.commit()
        return True
      except Exception as ex:
        print(&quot;Error to insert table&quot;)
        return False
  </code></pre>
  <p>I got the print in the log</p>
  <pre><code>Error to insert table
  -1  rows inserted in table accxounts
  </code></pre>