1
votes

I am using Apache Ignite 2.7.5 as Server and thin client in .Net core. When I'm doing operation related to cache put, get and load, etc .net core application automatically getting to crash.

So I want to handle exception inside for loop particular exception coming like for example IgniteCheckedException, BinaryInvalidTypeException, ClassNotFoundException, etc then throw from catch block and exit for loop otherwise continue for loop iteration if only Exception block.

public async void loadData(string configPath,List<JObject> dataList)
    {

        using (var ldr = _ignite.GetDataStreamer<string, Employee>(cacheName))
        {             

            foreach (var item in parsedObjectList)
            {
                try
                {
                    JObject keyObj = new JObject();
                    foreach (var keyName in keyArray)
                    {
                        keyObj[keyName.ToString()] = item[keyName.ToString()];
                    }

                    var serializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };

                    JsonConvert.PopulateObject(item.ToString(), emp, serializerSettings);

                    string json = JsonConvert.SerializeObject(keyObj, Formatting.None);

                    string base64EncodedKey = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));

                    await ldr.AddData(base64EncodedKey, emp);                   

                }
                catch (IgniteCheckedException ex)//how to handle here
                {
                    throw;
                }
                catch (BinaryInvalidTypeException ex)//how to handle here
                {
                    throw;
                }
                catch (ClassNotFoundException ex)//how to handle here
                {
                    throw;
                }
                catch (Exception ex)
                {
                //continue for loop if data parsing ,some normal exception
                    Console.WriteLine(ex);
                }
            }

        }
    }

Anyone suggests me, how to achieve this one in .net core c# application.

1
Can you point me to the method that is supposed to throw IgniteCheckedException here? I think it is strictly internal API exception and strictly Java one. - alamar
Yeah @alamar these exception relate to java but can you please guide me what will be the best way to handle exception for thin client in .net c#? - r08

1 Answers

1
votes

When you catch an exception from a thin .net client, the best course of action, as with any such client, to retry attempt, if it fails again, wait for some time, close connection, open new connection, try again. If that also fails, rethrow (write to log, fail current operation).