-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.html
43 lines (39 loc) · 1.03 KB
/
exceptions.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Using Exceptions</title>
</head>
<body onload="RunTest()">
<script language="JavaScript">
<!--
function InputException(msg) {
this.val = msg;
this.toString = function () {
return "Input Exception in " + this.val
};
}
function AreLetters(msg) {
var input = msg;
var re = new RegExp("[^a-zA-Z]");
if(input.match(re)) {
Oops = new InputException(input);
throw Oops;
}
}
function RunTest() {
document.writeln("<h1>Using Exceptions</h1>");
var input = prompt("Type Something", "");
try {
AreLetters(input);
document.writeln("<p>You only see this if the exception is not thrown</p>");
} catch (e) {
document.writeln("<p>" + e.toString() + "</p>");
document.close();
}
document.close();
}
//-->
</script>
</body>
</html>