Forum Xamarin.Forms

Iterative Try-Catch block?

I'm trying to parse data from a webpage (no API unfortunately) using _XPath _through _HTMLAgilityPack _but I'm having an issue. Right now my code looks like something like this (simplified):

Character character = new Character(); try { character.a = XPath expression goes here character.b = XPath expression goes here and so forth... }

Unfortunately each and every parsing expression can fail because the content of the page may be different from the most "common" one. My issue is that obviously the try... block stops as soon as it encounters an error, making it impossible to go further parsing the page. What would it be the best approach in this situation?

Obviously I could encompass each and every parsing expression in a try... block but that doesn't seem quite right and it definitely makes the whole thing less scalable and maintainable. I thought that maybe I could place every _XPath _expression in a list, iterate through that encompassing every iteration in a try... block and use _Reflection _to assign those (successful) results to the Character class properties but maybe there's something easier.

Sign In or Register to comment.