Skip to content

Commit 84f3991

Browse files
committed
Handle SecurityError in solution to exercise 9.2
1 parent 4945af5 commit 84f3991

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

code/solutions/19_2_color_picker.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@
1111

1212
tools["Pick color"] = function(event, cx) {
1313
var pos = relativePos(event, cx.canvas);
14-
var color = colorAt(cx, pos.x, pos.y);
14+
try {
15+
var color = colorAt(cx, pos.x, pos.y);
16+
} catch(e) {
17+
if (e instanceof SecurityError) {
18+
alert("Unable to access your picture's pixel data");
19+
return;
20+
} else {
21+
throw e;
22+
}
23+
}
1524
cx.fillStyle = color;
1625
cx.strokeStyle = color;
1726
};

0 commit comments

Comments
 (0)