Custom Division Function with Zero Division Check

  • Share this:

Code introduction


This custom function attempts to divide the first argument by the second argument. If the second argument is zero, it catches the exception and returns an error message.


Technology Stack : Exception handling

Code Type : Exception Handling Function

Code Difficulty :


                
                    
def aaaa(arg1, arg2):
    try:
        return arg1 / arg2
    except ZeroDivisionError:
        return "Cannot divide by zero"