Python Language Raise Custom Errors / Exceptions Catch custom Exception

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


This example shows how to catch custom Exception

class CustomError(Exception):

    raise CustomError('Can you catch me ?')
except CustomError as e:
    print ('Catched CustomError :{}'.format(e))
except Exception as e:
    print ('Generic exception: {}'.format(e))


Catched CustomError :Can you catch me ?

Got any Python Language Question?