Hi Team,
How to display the key name of the dictionary if the given key is not defined and we get keynotexception. In exception block bot has to log the key name of the dict.
KarthikBallary
Hi Team,
How to display the key name of the dictionary if the given key is not defined and we get keynotexception. In exception block bot has to log the key name of the dict.
KarthikBallary
we can check in advance with myDict.ContainsKey(“myKey”) and do not risk the exception key not present
There are many dict keys in the workflow. Any other way to pre check
You can try with this flow
I assume u have kept the activity in a loop
Keep the activity inside the TRY block of TRY CATCH activity, where that error is thrown and where u want to identify the key
If it failed it goes to CATCH Block where you can get to know whether the key is there or not using If condition
Condition be like
dict_variable.ContainsKey(currentkey)
If true it goes to then block that key is there and u can follow some steps to retry
If not there then it goes to Else block where u can capture the key that is missing like this in a assign activity
str_missingKey = Currentkey.ToString
Cheers @KarthikBallary
arrRequiredKey = new String(){“K1”,“K2”…}
arrRequiredKey.Except(myDict.Keys).toArray will give us all expected keys which are not present within the dict.
We can modify and adapt as well