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()
21     ->getMethod<jni::JString()>("getLocalizedMessage");
22   const auto message = getLocalizedMessage(this->self());
23   if (message != nullptr) {
24     return message->toStdString();
25   }
26 
27   return std::nullopt;
28 }
29 
30 jni::local_ref<JavaScriptEvaluateException> JavaScriptEvaluateException::create(
31   const std::string &message,
32   const std::string &jsStack
33 ) {
34   return JavaScriptEvaluateException::newInstance(
35     jni::make_jstring(message),
36     jni::make_jstring(jsStack)
37   );
38 }
39 
40 jni::local_ref<UnexpectedException> UnexpectedException::create(const std::string &message) {
41   return UnexpectedException::newInstance(
42     jni::make_jstring(message)
43   );
44 }
45 } // namespace expo
46