Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make try / catch continue to work after an error?

Parser code is available

try
{
   id_source = await ParsingAll(0, "#adv_id", "");   
   foto_path = await ParsingAll(1, "img[id='print_user_photo']", "src");
   position = await ParsingAll(0, "div.title.adv-title.newTitle > h1", "");
catch (Exception ex)
{
    Error?.Invoke(id_source + "- Error - ");    
}   

How to do if an error occurs in the string "foto_path", then after processing the try / catch error, the program continued to work and began to execute the string "position"?

like image 631
eusataf Avatar asked Dec 31 '25 01:12

eusataf


1 Answers

One way is that to add try catch inside your ParseAll method :

ParsingAll()
{
   try
   {

   }
   catch(Exception e)
   {
   }
}

and you can call them normally:

id_source = await ParsingAll(0, "#adv_id", "");   
foto_path = await ParsingAll(1, "img[id='print_user_photo']", "src");
position = await ParsingAll(0, "div.title.adv-title.newTitle > h1", "");

and return some status with result to tell if it was successful or not.

Or you will need to wrap it separately each of them so that the next statements should execute in case of that one fails:

try
{
    foto_path = await ParsingAll(1, "img[id='print_user_photo']", "src");
}
catch(Exception e)
{
}

position = await ParsingAll(0, "div.title.adv-title.newTitle > h1", "");

But this all depends on the program requirements how the flow will go.

like image 132
Ehsan Sajjad Avatar answered Jan 01 '26 16:01

Ehsan Sajjad