Am just wondering how to workaround my scenario,here is my code
try
{
bool b;
foreach (string file in files)
{
#region donloadfiles
if (b = file.Contains(story))
{
try
{
logger.Info("calling xml creation Method");
baseMeta(story, XML);
logger.Info("XML created");
}
catch (Exception ex)
{ logger.Error(ex.Message); throw; }
logger.Info("calling Download Method");
Download(file, story, xml, program);
logger.Info("Download Method processed successfully");
}
#endregion
}
}
catch (Exception ex)
{ logger.Error(ex.Message); throw; }
As promised,here is my main method contains try catch block
try
{
//update the status here in DB
Status = "Closed";
Update(status);
}
catch (Exception ex)
{
Status = "Failed";
Update(status);
break;
}
i have directory “for eg:C:\” my getlist method grab all the record and pass it to my foreach loop “foreach (string file in files)” then i have a condition
if (b = file.Contains(story)) to check any of my file have the name “story” then do some logic inside.this thing works good.
Now what am trying to do is,if none of the files are matching then i have to forcefully call the catch and throw to the main catch,am doing some logic update in my main catch.
Someone please advice me how can i workaround this scenario.
Thanks in advance
Keep a bool variable outside foreach loop. Set it to true if any file matches. if it is false at the end of foreach loop throw exception