-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrores.js
34 lines (32 loc) · 939 Bytes
/
errores.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function otraFuncion(){
serompe();
}
function serompe(){
//z no esta definida
return 3+z;
}
function seRompeAsincrona(cb){
//si no se pone el try catch dentro de setTimeout detecta error, por que esta funcion se ejecuta en otro hilo, y el hilo principal no tiene como detectar el error
setTimeout(()=>{
//probar eliminar este try catch, este try catch se ejecuta en el hilo de setTimeout
try{
return 3+z;
} catch(err){
console.error("error en funcion asincrona")
cb(err);
}
})
}
try{
//otraFuncion();
seRompeAsincrona(()=>{
console.log("ejecutando el callback")
});
}
catch(err){
console.error('error en la funcion');
//console.error(err);
console.error(err.message);
}
//sin try catch la función detiene toda la ejecución del programa y no se muestra el siguiente log
console.log("final del programa");