File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Roadmap/10 - EXCEPCIONES/python Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ #Excepciones y errores
2
+
3
+ try :
4
+ print (10 / 1 )
5
+
6
+ my_list = [1 ,2 ,3 ,4 ]
7
+ print (my_list [4 ])
8
+
9
+ except Exception as e :
10
+ print (f"ERROR: { e } " )
11
+
12
+ print ("Hola a todos" )
13
+
14
+
15
+ #EJERCICIO EXTRA
16
+
17
+ class StrTypeError (Exception ):
18
+ pass
19
+
20
+ def extra (param :list ):
21
+
22
+ if len (param ) < 3 :
23
+ raise IndexError ()
24
+ elif param [1 ] == 0 :
25
+ raise ZeroDivisionError ()
26
+ elif type (param [2 ]) != str :
27
+ raise StrTypeError ("El tercer elemento debe de ser una cadena de texto" )
28
+
29
+ print (param [2 ])
30
+ print (param [0 ]/ param [1 ])
31
+
32
+
33
+ try :
34
+ extra ([1 ,2 ,"Hola" ])
35
+ except IndexError as e :
36
+ print ("ERROR: el numero de elementos de la lista debe ser mayor de 2" )
37
+ except ZeroDivisionError as e :
38
+ print ("ERROR: el segundo elemento de la lista no puede ser cero" )
39
+ except StrTypeError as e :
40
+ print (f"ERROR: { e } " )
41
+ except Exception as e :
42
+ print (f"ERROR inesperado: { e } " )
43
+ finally :
44
+ print ("FIN" )
You can’t perform that action at this time.
0 commit comments