Else Keyword In Exception Handling

Overview:

 

Example:

def div(param1, param2):

     quotient = param1/param2;

     return quotient;

   

try:

    p1 = 1;

    p2 = 100;

    n1 = div(p1,p2);

    print("p1/p2 is %d"%n1);

 

    p1 = 2;

    p2 = 100;

    n1 = div(p1,p2);

    print("p1/p2 is %d"%n1);

except Exception as Ex:

    print("Exception: %s"%Ex);

else:

    print("All div operations successful");

 

Output:

p1/p2 is 0

p1/p2 is 0

All div operations successful


Copyright 2020 © pythontic.com