try_catch.h 767 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GIN_TRY_CATCH_H_
  5. #define GIN_TRY_CATCH_H_
  6. #include <string>
  7. #include "base/memory/raw_ptr.h"
  8. #include "gin/gin_export.h"
  9. #include "v8/include/v8-exception.h"
  10. namespace gin {
  11. // TryCatch is a convenient wrapper around v8::TryCatch.
  12. class GIN_EXPORT TryCatch {
  13. public:
  14. explicit TryCatch(v8::Isolate* isolate);
  15. TryCatch(const TryCatch&) = delete;
  16. TryCatch& operator=(const TryCatch&) = delete;
  17. ~TryCatch();
  18. bool HasCaught();
  19. std::string GetStackTrace();
  20. private:
  21. raw_ptr<v8::Isolate> isolate_;
  22. v8::TryCatch try_catch_;
  23. };
  24. } // namespace gin
  25. #endif // GIN_TRY_CATCH_H_