-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorHandling.js
More file actions
51 lines (42 loc) · 1 KB
/
errorHandling.js
File metadata and controls
51 lines (42 loc) · 1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//Custom Error:
var MyError = function(){
console.log("An error detected");
throw "this error is because you have entered a string";
}
function getName(name){
if(typeof(name) =="string"){
throw MyError();
}
}
getName('Mustafa');
//Error Handling Using if..else:
function Computer(myComputer){
if(typeof(myComputer) == "string"){
if(myComputer == 'DELL'){
console.log('It\'s DELL!');
}
if(myComputer == 'TOSHIBA'){
console.log('It\'s TOSHIBA!');
}
if(myComputer == 'hp'){
console.log('It\'s Helwet Packard!');
}else{
console.log('Unrecognized!');
}
}else{
console.log("Cannot work because it's not a string");
}
}
Computer("DELL");
//Error Handling Using try..catch:
function CapitalizeName(name){
try{
var x = name.toUpperCase();
}catch(error){
throw "This is a Syntax Error";
}finally{
console.log('Done')
}
return x;
}
console.log(CapitalizeName(890));