1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo) 2 3 #pragma once 4 5 #include <fbjni/fbjni.h> 6 7 namespace jni = facebook::jni; 8 9 namespace expo { 10 /** 11 * A convenient wrapper for the Kotlin CodedException. 12 * It can be used with the `jni::throwNewJavaException` function to throw a cpp exception that 13 * will be automatically changed to the corresponding Java/Kotlin exception. 14 * `jni::throwNewJavaException` creates and throws a C++ exception which wraps a Java exception, 15 * so the C++ flow is interrupted. Then, when translatePendingCppExceptionToJavaException 16 * is called at the topmost level of the native stack, the wrapped Java exception is thrown to the java caller. 17 */ 18 class CodedException : public jni::JavaClass<CodedException, jni::JThrowable> { 19 public: 20 static auto constexpr kJavaDescriptor = "Lexpo/modules/kotlin/exception/CodedException;"; 21 22 static jni::local_ref<CodedException> create(const std::string &message); 23 }; 24 25 /** 26 * A convenient wrapper for the Kotlin JavaScriptEvaluateException. 27 */ 28 class JavaScriptEvaluateException 29 : public jni::JavaClass<JavaScriptEvaluateException, CodedException> { 30 public: 31 static auto constexpr kJavaDescriptor = "Lexpo/modules/kotlin/exception/JavaScriptEvaluateException;"; 32 33 static jni::local_ref<JavaScriptEvaluateException> create( 34 const std::string &message, 35 const std::string &jsStack 36 ); 37 }; 38 } // namespace expo 39