From d8974ddb1ced59bee9a12798501797098c1e11b5 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:36:07 -0500 Subject: [PATCH] Nested try/except fix --- src/database/sql_database.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/database/sql_database.py b/src/database/sql_database.py index e6e9306..29e5948 100644 --- a/src/database/sql_database.py +++ b/src/database/sql_database.py @@ -257,36 +257,34 @@ class SQL_Database: # Getters and setter for class - def get_config_id(self): try: # return the config id if its already set - self.__config_id = "something" - except: - # Get the most resent run from config table. - pass + self.config_id = "something" + except: # config_id and config table dont exist: Tell the user print("""You are required to run a ga before you can connect to the database. Run ga.evolve()""") - break def get_conn(self): """Conn """ + try: # Return if the connection has already been set - return self.__conn - except: - # Check if you can connect to the database named in ga - self.__conn = self.create_connection(ga.database_name) + return self.conn except: - # See if the default database exists - self.__conn = self.create_connection("database.db") - except: - # if the connection - print("""You are required to run a ga before you - can connect to the database. Run ga.evolve()""") - break + + try: + # Check if you can connect to the database named in ga + self.conn = self.create_connection(ga.database_name) + return self.conn + + except: + # if the connection + print("""You are required to run a ga before you + can connect to the database. Run ga.evolve()""") + return