Advertisement
teslariu

lanzamiento de excepciones

Aug 13th, 2022
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # script que abre una base de datos
  5. """
  6. try:
  7. pass # abrir la base datos
  8. except Exception: # acá iría la excepción si no puedo acceder a la base
  9. print("No se pudo acceder a la base")
  10. else:
  11. pass # codigo a ejecutar si la base se puede abrir
  12. finally: # se ejecuta siempre
  13. # primero debo cerrar la conexion a la base
  14. print("Chau")
  15. """
  16. # Lanzamiento de excepciones
  17. def sumar(a,b):
  18. """Función que toma como argumentos a dos nros y devuelve la suma"""
  19. if not isinstance(a,(int,float)) or not isinstance(b,(int,float)):
  20. raise TypeError("Se requieren dos nros")
  21. return a+b
  22.  
  23. print(sumar([1,2],[25,14]))
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement