top of page
Search

Paradigm: Try, Except, Finally


Imperative Programming



def division_error_handling(num1, num2):
    try:
        result = num1 / num2
        print(f"The result is {result}")
    except ZeroDivisionError:
        print("Error: Cannot divide by zero.")
    except ValueError:
        print("Error: Please enter a valid number.")
    finally:
        print("Operation completed.")

division_error_handling(num1=5, num2=0)






5 views

Comments


bottom of page