Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Prevention

We might try to prevent the exceptions generated by the system, but even if succeed in preventing it, how do we indicate that there was an issue? For example with the input?

def div(a, b):
    if b == 0:
        # raise Exception("Cannot divide by zero")
        print("Cannot divide by zero")
        return None

    print("before")
    print(a/b)
    print("after")

div(1, 0)