Introduce TryRethrowScope::TakeException to get and clear the exception

... as a drive-by, make fields private.

Change-Id: Idc876ea788c15badf3546ef6f688726608c766ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7098864
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1538024}
diff --git a/third_party/blink/renderer/platform/bindings/exception_state.h b/third_party/blink/renderer/platform/bindings/exception_state.h
index 62fbb680..572b857 100644
--- a/third_party/blink/renderer/platform/bindings/exception_state.h
+++ b/third_party/blink/renderer/platform/bindings/exception_state.h
@@ -237,9 +237,18 @@
     }
   }
 
-  bool HasCaught() { return try_catch_.HasCaught(); }
-  v8::Local<v8::Value> GetException() { return try_catch_.Exception(); }
+  bool HasCaught() const { return try_catch_.HasCaught(); }
+  v8::Local<v8::Value> GetException() const { return try_catch_.Exception(); }
 
+  static v8::Local<v8::Value> TakeException(v8::TryCatch& try_catch) {
+    v8::Local<v8::Value> result = try_catch.Exception();
+    try_catch.Reset();
+    return result;
+  }
+
+  v8::Local<v8::Value> TakeException() { return TakeException(try_catch_); }
+
+ private:
   v8::TryCatch try_catch_;
   ExceptionState& exception_state_;
 };