-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path26-error-manual.html
51 lines (43 loc) · 1.33 KB
/
26-error-manual.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error Manual</title>
</head>
<body>
<script>
class ValidationError extends Error {
constructor (message, field) {
super(message);
this.field = field;
}
}
class MathUntil {
static sum(...numbers) {
if (numbers.length === 0 ){
throw new ValidationError("Total parameter harus lebih dari 0", "numbers");
}
let result = 0
for (const number of numbers) {
result += number;
}
return result;
}
}
try {
console.info(MathUntil.sum());
} catch (error) {
if (error instanceof ValidationError) {
console.error(`Terjadi error di field ${error.field} dengan error : ${error.message}`);
} else {
console.error(`Terjdi error : ${error.message}`);
}
} finally {
console.info("Kode program selesai");
}
console.info("Kode Program Tidak Akan Berhenti");
</script>
</body>
</html>