excépciones personalizadas

This commit is contained in:
cmoreno 2026-08-20 19:43:32 -03:00
parent d0f39b6ab5
commit 6aa87585a6
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,16 @@
class NumeroInvalidoError (Exception):
pass
try:
nunero= int(input("ingrese un numero"))
if nunero < 0 :
print("ingrese un numero entero")
raise NumeroInvalidoError
except NumeroInvalidoError:
print("ocurrio un error")
else:
print("el valor es positivo")
finally:
print("finalizado")

14
clase_6/index.py Normal file
View File

@ -0,0 +1,14 @@
try:
lista= ["Hola",1, 7, True]
indice= int(input("Ingrese el numero de indice"))
print(lista[indice])
except ValueError:
print("ingrese un valor entero")
except IndexError :
print(f"ocurrió un error, error de indice")
else:
print(f"el indice es {lista[3]}")
finally:
print("Programa finalizado")