-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrycatch.js
More file actions
33 lines (29 loc) · 822 Bytes
/
trycatch.js
File metadata and controls
33 lines (29 loc) · 822 Bytes
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
//Errores con funciones
const myFunction = (val) =>{
if(typeof val === "number"){
return val * 2;
}
throw new Error ("Solo se pueden realizar con numeros :)")
}
console.log(myFunction(12));
// console.log(myFunction("Hola"));
//Errores con try catch
const numero = 8;
const cadena = `string`
try {
const doble = myFunction(numero);
//const doble = myFunction(cadena);
console.log(doble);
console.log(`Ejecutando de manera correcta`);
} catch(e){
console.log(`¡Fatal! No se eejecuto correctamente.`);
console.log(`"e" tiene como contenido lo siguiente: ${e}`);
}finally{ console.log(`Siempre me ejecuto, haya error o no`);}
/** Existen tipos de errores ya predeterminados por el lenguaje
*
* INTERNAL ERROR
* SYNTAX ERROR
* TYPE ERROR
* RANGE ERROR
* REFERENCE ERROR
*/