mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 22:03:11 -07:00
Wrap json parsing in try/catch
This commit is contained in:
parent
f1efe82c7e
commit
10857b41d2
1 changed files with 33 additions and 3 deletions
|
@ -530,7 +530,22 @@ bool CurrencyDataLoader::TryParseStaticData(_In_ String^ rawJson, _Inout_ vector
|
||||||
staticData.resize(size_t{ data->Size });
|
staticData.resize(size_t{ data->Size });
|
||||||
for (unsigned int i = 0; i < data->Size; i++)
|
for (unsigned int i = 0; i < data->Size; i++)
|
||||||
{
|
{
|
||||||
JsonObject^ obj = data->GetAt(i)->GetObject();
|
JsonObject ^ obj;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
obj = data->GetAt(i)->GetObject();
|
||||||
|
}
|
||||||
|
catch (COMException ^ e)
|
||||||
|
{
|
||||||
|
if (e->HResult == E_ILLEGAL_METHOD_CALL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < values.size(); j++)
|
for (size_t j = 0; j < values.size(); j++)
|
||||||
{
|
{
|
||||||
|
@ -557,7 +572,7 @@ bool CurrencyDataLoader::TryParseStaticData(_In_ String^ rawJson, _Inout_ vector
|
||||||
|
|
||||||
bool CurrencyDataLoader::TryParseAllRatiosData(_In_ String^ rawJson, _Inout_ CurrencyRatioMap& allRatios)
|
bool CurrencyDataLoader::TryParseAllRatiosData(_In_ String^ rawJson, _Inout_ CurrencyRatioMap& allRatios)
|
||||||
{
|
{
|
||||||
JsonArray^ data = nullptr;
|
JsonArray ^ data = nullptr;
|
||||||
if (!JsonArray::TryParse(rawJson, &data))
|
if (!JsonArray::TryParse(rawJson, &data))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -568,7 +583,22 @@ bool CurrencyDataLoader::TryParseAllRatiosData(_In_ String^ rawJson, _Inout_ Cur
|
||||||
allRatios.clear();
|
allRatios.clear();
|
||||||
for (unsigned int i = 0; i < data->Size; i++)
|
for (unsigned int i = 0; i < data->Size; i++)
|
||||||
{
|
{
|
||||||
JsonObject^ obj = data->GetAt(i)->GetObject();
|
JsonObject ^ obj;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
obj = data->GetAt(i)->GetObject();
|
||||||
|
}
|
||||||
|
catch (COMException^ e)
|
||||||
|
{
|
||||||
|
if (e->HResult == E_ILLEGAL_METHOD_CALL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rt is ratio, An is target currency ISO code.
|
// Rt is ratio, An is target currency ISO code.
|
||||||
double relativeRatio = obj->GetNamedNumber(StringReference(RATIO_KEY));
|
double relativeRatio = obj->GetNamedNumber(StringReference(RATIO_KEY));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue