I am writing an application that I can combine tasks with several steps. I have code similar to the one below and I want to know if this is the usual way to handle exceptions. This code will probably never be noticed by anyone, but it may be so, so I would like to know that I am handling exceptions as expected.
IEnumerable<Task> Tasks;
foreach(var task in Tasks)
{
try
{
foreach(var step in task.Steps)
{
try
{
step.Execute();
}
catch(Exception ex)
{
LogStepError(step, ex);
throw;
}
}
}
catch(Exception ex)
{
LogTaskFailure(task);
}
finally
{
}
}
interface ITaskStep
{
void Execute()
{
}
}
I also wanted to add that the execution steps implement the ITaskStep interface, so the Execute implementation is not my own (well, in this case, but someone can implement the interface). My code just loads the library and runs any ITasks and their ITaskSteps.
source
share