print(' Hay principalmente 2 tipos de errores: de sintaxis y excepciones ') while True : try: x = int(input('Excepcion si no se ingresa un ENTERO ->')) break except ValueError: print('Se puede salir con Ctrl-C') while True : try: x = int(input('Excepcion si no se ingresa un ENTERO ->')) break except (ValueError, KeyboardInterrupt): print('Ya, no se puede salir y con Ctrl-C') print(''' ... except (RuntimeError, TypeError, NameError): ... pass ''') class B(Exception): pass class C(B): pass class D(C): pass for cls in [B, C, D]: try: raise cls() except D: print("D", D) except C: print("C", C) except B: print("B", B) print('') for cls in [B, C, D]: try: raise cls() except B: print("B") except D: print("D") except C: print("C") print('') import sys try: f = open('mifile.txt') s = f.readline() i = int(s.strip()) except OSError as err: print("Error OS: {0}".format(err)) except ValueError: print("No pude convertir el dato a entero.") except: print("Error inesperador: ", sys.exc_info()[0]) raise ''' for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('no pude abrir', arg) else: print(arg, 'tiene', len(f.readlines()), 'lineas') f.close() ''' try: raise Exception('carne', 'huevos') except Exception as inst: print(type(inst)) print(inst.args) print(inst) #x, y = inst #print('x: ',x ,'y: ',y) """ >>> raise RuntimeError('Error error bip bap bip! no computa! bip bap!') Traceback (most recent call last): File "", line 1, in RuntimeError: Error error bip bap bip! no computa! bip bap! """ # RELANZANDO la EXCEPcion para se manejada en otro contexto. try: raise NameError('y bueno un error comĂșn') except NameError: print('ee.. salto un except!') raise