Turn on exceptions in test tools.

This allows us to test things that, e.g., throw std::bad_alloc.

Change-Id: I6409159b89f1d93d403b1a1f40539cf2531a8b68
Reviewed-on: https://skia-review.googlesource.com/34982
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index afa38a1..d7a179d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -883,6 +883,9 @@
         ":skia_private",
       ]
 
+      configs -= [ "//gn:no_exceptions" ]
+      configs += [ "//gn:yes_exceptions" ]
+
       if (!defined(deps)) {
         deps = []
       }
@@ -896,6 +899,8 @@
       shared_library("lib" + target_name) {
         forward_variables_from(invoker, "*", [ "is_shared_library" ])
         configs += [ ":skia_private" ]
+        configs -= [ "//gn:no_exceptions" ]
+        configs += [ "//gn:yes_exceptions" ]
         testonly = true
       }
     } else {
@@ -903,6 +908,8 @@
       executable(_executable) {
         forward_variables_from(invoker, "*", [ "is_shared_library" ])
         configs += [ ":skia_private" ]
+        configs -= [ "//gn:no_exceptions" ]
+        configs += [ "//gn:yes_exceptions" ]
         testonly = true
       }
     }
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
index 7be1617..06cff4e 100644
--- a/gn/BUILD.gn
+++ b/gn/BUILD.gn
@@ -258,11 +258,16 @@
 }
 
 config("no_exceptions") {
-  # Exceptions are disabled by default on Windows.  (Use /EHsc to enable them.)
+  # Exceptions are disabled by default on Windows.  (Use :yes_exceptions to enable them.)
   if (!is_win) {
     cflags_cc = [ "-fno-exceptions" ]
   }
 }
+config("yes_exceptions") {
+  if (is_win) {
+    cflags_cc = [ "/EHsc" ]
+  }
+}
 
 config("warnings") {
   cflags = []
diff --git a/gn/tests.gni b/gn/tests.gni
index c2f3759..51d1d08 100644
--- a/gn/tests.gni
+++ b/gn/tests.gni
@@ -62,6 +62,7 @@
   "$_tests/EGLImageTest.cpp",
   "$_tests/EmptyPathTest.cpp",
   "$_tests/EncodeTest.cpp",
+  "$_tests/ExceptionTest.cpp",
   "$_tests/ExifTest.cpp",
   "$_tests/F16StagesTest.cpp",
   "$_tests/FillPathTest.cpp",
diff --git a/tests/ExceptionTest.cpp b/tests/ExceptionTest.cpp
new file mode 100644
index 0000000..85e6dca
--- /dev/null
+++ b/tests/ExceptionTest.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+
+// Just a little meta-test that our test tools can compile and link with exceptions enabled.
+DEF_TEST(Exceptions, r) {
+    bool exception_caught = false;
+    try {
+        throw 42;
+    } catch (...) {
+        exception_caught = true;
+    }
+    REPORTER_ASSERT(r, exception_caught);
+}