Yes. it should be possible. as an example i found this from the Errors and Exceptions documentation of python.
In this example the exceptions are put on a list. The list is iterated in the for loop and the exceptions are raised one by one..
class B(Exception):
pass
class C(B):
pass
class D(C):
pass
for cls in [B, C, D]:
try:
raise cls()
except D:
print("D")
except C:
print("C")
except B:
print("B")
For your purpose maybe it would look something like:
class Userdoesnotexist(Exception):
def __init__(self, message):
# Call the base class constructor with the parameters it needs
super().__init__(message)
class Userexists(Exception):
def __init__(self, message):
# Call the base class constructor with the parameters it needs
super().__init__(message)
def lambda_handler(event, context):
verif = boto3.resource('iam')
client_iam = boto3.client('iam')
user = verif.User('Tom')
try:
user.load()
if verif.exceptions.NoSuchEntityException:
raise Userdoesnotexist("user does not exist.")
if ex.response['Error']['Code'] != 'NoSuchEntityException':
raise Userexists("user exist.")
Probably it is not perfect but you could take a look to this thread.