-
Notifications
You must be signed in to change notification settings - Fork 0
/
044-Error_Handle.js
63 lines (51 loc) · 1.3 KB
/
044-Error_Handle.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Author : Jaydatt Patel
error handling:
try{
} catch(){
}catch(){
}......{
}finally{
}
Here are some of the most common errors in JavaScript:
- ReferenceError
- SyntaxError : syntax error can not work with try and catch block
- TypeError
- RangeError
There are some other errors in JavaScript. These other errors include:
- AggregateError
- Error
- InternalError
- URIError
*/
console.log("\n----------Reference Error");
try {
console.log(username);
} catch (error) {
console.log("ReferenceError: username is not defined");
}
try {
xyzFunction();
} catch (error) {
console.log("ReferenceError: xyzFunction() is not defined");
}
console.log("\n----------Syntax Error");
console.log(
"Syntax error must ne solved before run program",
"This problem can not be resolved using try and catch block"
);
console.log("\n----------Type Error");
try {
"hello".get();
} catch (error) {
console.log('TypeError:"hello".get is not a function');
}
console.log("\n----------Range Error");
try {
console.log((10).toString(2)); // '1010'
console.log((10).toString(50)); // error, rnage for tostring(2 to 36)
} catch (error) {
console.log(
"RangeError: toString() radix argument must be between 2 and 36 at Number.toString "
);
}