1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo) 2 3 #include "Exceptions.h" 4 5 namespace jni = facebook::jni; 6 7 namespace expo { 8 9 jni::local_ref<CodedException> CodedException::create(const std::string &message) { 10 return CodedException::newInstance(jni::make_jstring(message)); 11 } 12 13 std::string CodedException::getCode() { 14 const auto getCode = this->getClass()->getMethod<jni::JString()>("getCode"); 15 const auto code = getCode(this->self()); 16 return code->toStdString(); 17 } 18 19 std::optional<std::string> CodedException::getLocalizedMessage() { 20 const auto getLocalizedMessage = this->getClass()->getMethod<jni::JString()>("getLocalizedMessage"); 21 const auto message = getLocalizedMessage(this->self()); 22 if (message != nullptr) { 23 return message->toStdString(); 24 } 25 26 return std::nullopt; 27 } 28 29 jni::local_ref<JavaScriptEvaluateException> JavaScriptEvaluateException::create( 30 const std::string &message, 31 const std::string &jsStack 32 ) { 33 return JavaScriptEvaluateException::newInstance( 34 jni::make_jstring(message), 35 jni::make_jstring(jsStack) 36 ); 37 } 38 } // namespace expo 39