File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed
Roadmap/10 - EXCEPCIONES/python Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ #manejo de errores en los lenguajes de programación
2
+
3
+ """
4
+ Ejercicio
5
+ """
6
+ try :
7
+
8
+ print (10 / 1 )
9
+
10
+ print ([1 , 2 , 3 , 4 ] [4 ])
11
+
12
+ except Exception as e :
13
+
14
+ print (f"Se ha producido un error:{ e } ({ type (e ).__name__ } )" )
15
+
16
+
17
+
18
+ """
19
+ Extra
20
+
21
+ """
22
+ class StrTypeError (Exception ):
23
+ pass
24
+
25
+ def process_params (parameters : list ):
26
+
27
+ if len (parameters ) < 3 :
28
+ raise IndexError ()
29
+
30
+ elif parameters [1 ] == 0 :
31
+ raise ZeroDivisionError ()
32
+
33
+ elif type (parameters [2 ]) == str :
34
+ raise StrTypeError ("El segundo elemento no puede ser una cadena de texto" )
35
+
36
+ print (parameters [2 ])
37
+ print (parameters [0 ]/ parameters [1 ])
38
+ print (parameters [2 ] + 5 )
39
+
40
+ try :
41
+ process_params ([1 , 2 , 3 , 4 ])
42
+
43
+ except IndexError as e :
44
+ print ("El número de elementos de la lista debe ser mayor que dos." )
45
+
46
+ except ZeroDivisionError as e :
47
+ print ("El segundo elemento de la lista no puede ser un cero." )
48
+
49
+ except StrTypeError as e :
50
+ print (f"{ e } " )
51
+
52
+ except Exception as e :
53
+ print (f"El programa finaliza sin detenerse." )
54
+
55
+ else :
56
+ print ("No se ha producido ningún error." )
57
+
58
+ finally :
59
+ print ("El programa finaliza sin detenerse." )
60
+
61
+
62
+ print ("Se ha producido un error" )
63
+
64
+
65
+ #process_params([1, 2, 3])
66
+
67
+
You can’t perform that action at this time.
0 commit comments