Skip to content

Commit f2b4712

Browse files
committed
Throw Error instances instead of strings
1 parent 99a7865 commit f2b4712

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

jsonpointer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var untilde = function(str) {
88
case "~1":
99
return "/";
1010
}
11-
throw("Invalid tilde escape: " + m);
11+
throw new Error("Invalid tilde escape: " + m);
1212
});
1313
}
1414

@@ -38,21 +38,21 @@ var traverse = function(obj, pointer, value) {
3838

3939
var validate_input = function(obj, pointer) {
4040
if(typeof obj !== "object") {
41-
throw("Invalid input object.");
41+
throw new Error("Invalid input object.");
4242
}
4343

4444
if(pointer === "") {
4545
return [];
4646
}
4747

4848
if(!pointer) {
49-
throw("Invalid JSON pointer.");
49+
throw new Error("Invalid JSON pointer.");
5050
}
5151

5252
pointer = pointer.split("/");
5353
var first = pointer.shift();
5454
if (first !== "") {
55-
throw("Invalid JSON pointer.");
55+
throw new Error("Invalid JSON pointer.");
5656
}
5757

5858
return pointer;
@@ -69,7 +69,7 @@ var get = function(obj, pointer) {
6969
var set = function(obj, pointer, value) {
7070
pointer = validate_input(obj, pointer);
7171
if (pointer.length === 0) {
72-
throw("Invalid JSON pointer for set.")
72+
throw new Error("Invalid JSON pointer for set.")
7373
}
7474
return traverse(obj, pointer, value);
7575
}

0 commit comments

Comments
 (0)