I would like my program to exit regardless of the type of the exception that occurred. However, depending on the type of the exception, I want to log a different error message. How could I achieve this with less code repetitions? Following is the code I currently use:
try:
<code>
except Exception1:
self.logger.exception('Error message 1')
self.logger.error('Aborting')
sys.exit()
except Exception2:
self.logger.exception('Error message 2')
self.logger.error('Aborting')
sys.exit()
except Exception:
self.logger.exception('Unexpected error')
self.logger.error('Aborting')
sys.exit()