viernes, 1 de noviembre de 2024

Regular try , exception finally and Custom Exception error.

try:

    n = 10

    if n < 20:

        raise ValueError("n must be at least 20")  # Raising a ValueError with a message

except ValueError as e:

    print("An error has occurred:", e)

finally:

    print("Code completed.")


--------

Custom  Exception error.


 class CustomError(Exception):

    pass


try:

    raise CustomError("This is a custom error message.")

except CustomError as e:

    print("An error has occurred:", e)

finally:

    print("Code completed.")


No hay comentarios:

Publicar un comentario