Python exception handling with GUI and database connectivity