[Python] How to raise an Exception and still continue the main code?

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    Given the following simple example:

    while True:
    readme = input("Write here something:")
    if readme == "":
    raise Exception("That was empty!")


    (1) How can the main code / loop continue to work after an Exception has been thrown? (2) And if we simultaneously run another thread, how can we catch the Exception in there?

    Is it possible to do this without having a try/except block inside the loop?

    Continue reading...

Compartilhe esta Página