diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -651,7 +651,7 @@ error = e.what(); } - this->cryptoThread->scheduleTask([=]() { + taskType cryptoJob = [=]() { std::string error; this->contentCryptoModule.reset(new crypto::CryptoModule( this->publicCryptoAccountID, @@ -688,7 +688,13 @@ this->jsInvoker_->invokeAsync( [=]() { promise->resolve(jsi::Value::undefined()); }); - }); + }; + try { + this->cryptoThread->scheduleTask(cryptoJob); + } catch (const std::exception &e) { + error = e.what(); + this->jsInvoker_->invokeAsync([=]() { promise->reject(error); }); + } }; GlobalDBSingleton::instance.scheduleOrRunCancellable( job, promise, this->jsInvoker_);