Skip to content

Commit

Permalink
Handle C++/WinRT errors
Browse files Browse the repository at this point in the history
  • Loading branch information
purejava committed Oct 23, 2024
1 parent 02168f5 commit de97298
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,20 @@ jbyteArray JNICALL Java_org_cryptomator_windows_keychain_WinHello_00024Native_se

return vectorToJbyteArray(env, iBufferToVector(encryptedBuffer));

} catch (winrt::hresult_error const& hre) {
HRESULT hr = hre.code();
winrt::hstring message = hre.message();
std::wcout << L"Error: " << message.c_str() << L" (HRESULT: 0x" << std::hex << hr << L")" << std::endl;
auto byteArray = env->NewByteArray(0);
return byteArray;
} catch (const std::exception& e) {
std::cout << "Warning: " << e.what() << std::endl;
auto byteArray = env->NewByteArray(0);
return byteArray;
} catch (...) {
std::cout << "Caught an unknown exception" << std::endl;
auto byteArray = env->NewByteArray(0);
return byteArray;
}
}

Expand Down Expand Up @@ -178,9 +188,19 @@ jbyteArray JNICALL Java_org_cryptomator_windows_keychain_WinHello_00024Native_ge

return vectorToJbyteArray(env, iBufferToVector(decryptedBuffer));

} catch (winrt::hresult_error const& hre) {
HRESULT hr = hre.code();
winrt::hstring message = hre.message();
std::wcout << L"Error: " << message.c_str() << L" (HRESULT: 0x" << std::hex << hr << L")" << std::endl;
auto byteArray = env->NewByteArray(0);
return byteArray;
} catch (const std::exception& e) {
std::cout << "Warning: " << e.what() << std::endl;
auto byteArray = env->NewByteArray(0);
return byteArray;
} catch (...) {
std::cout << "Caught an unknown exception" << std::endl;
auto byteArray = env->NewByteArray(0);
return byteArray;
}
}

0 comments on commit de97298

Please sign in to comment.