You can use the try block to handle known error. The exception block should only catch known exceptions. Handling unexpected errors can cause your code to do something wrong and hide bugs. If there are no errors, the else clause is executed and you can prevent unexpected errors by not executing that code in the try block. Syntax-
try:
# YOUR CODE WITH POSSIBLE EXCEPTION
except KnownException as the_exception:
# HANDLE KNOWN EXCEPTION
else:
# CODE IF THERE IS NO EXCEPTION