Continuing execution after caught exception

  • Thread starter Thread starter Tolga Erdogus
  • Start date Start date
T

Tolga Erdogus

Hi,

I have the following code:

for (int i=0;i<childOptimizations.Length;i++) //for each partition

{

row = childOptimizations;

if (i==0)

dataManager.UpdateAvailabilityWithLegsFromExistingTrips(System.Convert.ToInt
32(row["SCHOPT_ID"]));

else

dataManager.UpdateAvailabilityWithLegsFromExistingOptimization(System.Conver
t.ToInt32(previousRow["SCHOPT_ID"]),System.Convert.ToInt32(row["SCHOPT_ID"])
);



optimizationEngine.optimize(System.Convert.ToInt32(row["SCHOPT_ID"]));



catch

{

}

childOptimizations=dataManager.SCHEDULE_OPTIMIZATION.Select("PARENT_SCHOPT_I
D="+optimizationID);

previousRow=childOptimizations;

}



Even though the optimizationEngine.optimize might thorw an exception, I
still want to the loop and run the other optimizations.

I know I can turn optimizationEngine.optimize method to return an error code
instead of throwing an exception, but I am baffled as to why I can't
continue the execution with optimizationEngine.optimize throwing an
exception.



Thanks
 
Hi:

You should put the "optimizationEngine.optimize(.......);" inside another
nested try-catch block
Ex:

try
{
// Put here the code you have


// put this line into the nested try catch block
// optimizationEngine.optimize(System.Convert.ToInt32(row["SCHOPT_ID"]));
try
{

optimizationEngine.optimize(System.Convert.ToInt32(row["SCHOPT_ID"]));
}
catch
{
// skip the exeption
}

// the program flow continues here, even when optimizationEngine.optimize
threw an exception


}
catch
{
}



optimizationEngine.optimize(System.Convert.ToInt32(row["SCHOPT_ID"]));

Tolga Erdogus said:
Hi,

I have the following code:

for (int i=0;i<childOptimizations.Length;i++) //for each partition

{

row = childOptimizations;

if (i==0)

dataManager.UpdateAvailabilityWithLegsFromExistingTrips(System.Convert.ToInt
32(row["SCHOPT_ID"]));

else
dataManager.UpdateAvailabilityWithLegsFromExistingOptimization(System.Convert.ToInt32(previousRow["SCHOPT_ID"]),System.Convert.ToInt32(row["SCHOPT_ID"])
);



optimizationEngine.optimize(System.Convert.ToInt32(row["SCHOPT_ID"]));



catch

{

}
childOptimizations=dataManager.SCHEDULE_OPTIMIZATION.Select("PARENT_SCHOPT_I
D="+optimizationID);

previousRow=childOptimizations;

}



Even though the optimizationEngine.optimize might thorw an exception, I
still want to the loop and run the other optimizations.

I know I can turn optimizationEngine.optimize method to return an error code
instead of throwing an exception, but I am baffled as to why I can't
continue the execution with optimizationEngine.optimize throwing an
exception.



Thanks
 
Back
Top