0

I have four different classes for four different JSON messages. The messages always come together and I need to handle them at the same time. The code is in one try - catch block and I search the right class by deserializing the JSON.

var convertedObject = JsonConvert.DeserializeObject<Class>(message);

but this three times throw an exception ann ones successfully continue. What I want to do is check first class, if error check another class up to four and only if no class matches throw an exception. Is this possible in one try - catch block?

Thanks a lot

soldous
  • 111
  • 1
  • 9
  • A [mcve] really would be awesome. – Fildor Feb 28 '19 at 13:38
  • @Crowcoder was right. I implement checks if the JSON contains words which are specific for every JSON as Dude Pascalou did in his question in provided link and it works now. – soldous Feb 28 '19 at 14:29

1 Answers1

0

Looks like you want to retry the same operation (in your case deserialization to a model) multiple times and then take a decision. You could consider using Polly.Retry for this purpose. See the linked documentation for an example

Rahul
  • 76,197
  • 13
  • 71
  • 125