Reputation: 95
I have a complex code in python with condition inside try:
try:
if condition is True: execute the code
else: go to exception and don't execute the code
except:
execute the except statement
I want to exit the try statement if condition is met
Upvotes: 0
Views: 1022
Reputation: 378
Just manually raise an exception:
try:
if condition:
your code
else:
raise Exception('Exception message')
except:
# except code here
Upvotes: 4