Skip to content

Commit 35313f3

Browse files
committed
#10 - javascript
1 parent bf2787e commit 35313f3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
try{
2+
let nums = [0, 1, 2, 3];
3+
let n = 5;
4+
if(n > nums.length) throw new Error('Ese indice no existe en este array');
5+
else console.log(nums[n]);
6+
}catch(e){
7+
console.log(e.toString())
8+
}
9+
10+
console.log('\n el programa sigue\n\n\n');
11+
12+
13+
/////////////////////////////////////////////////////////
14+
// Extra
15+
function excepciones(param1, param2){
16+
if((param1 + param2) <= 0) throw new Error('El resultado es negativo o 0');
17+
if(param1 < 0) throw new Error('El primer número es negativo');
18+
if(param2 < 0) throw new Error('El segundo número es negativo');
19+
console.log('No se ha producido ningun error!');
20+
}
21+
22+
try{
23+
excepciones(-2, 2);
24+
excepciones(-2, 20);
25+
excepciones(10, -2);
26+
excepciones(10, 2);
27+
}catch(e){
28+
console.log(e.toString());
29+
}finally{
30+
console.log('El programa finalizó');
31+
}

0 commit comments

Comments
 (0)