I am writing an app that I can feed tasks with multiple steps. I have some code similar to what's below and I want to know if this is the normal way to handle exceptions. This code will probably never be seen by anyone else, but it could be, so I'd like to know I'm handling the exceptions as anyone would expect.
IEnumerable<Task> Tasks;
foreach(var task in Tasks)
{
try
{
//boiler plate prep for task (loading libraries, connecting, logging start, etc)
foreach(var step in task.Steps)
{
try
{
step.Execute();
}
catch(Exception ex)
{
LogStepError(step, ex);
throw;
}
}
//Notify parties task has been completed successfully, log task completion
}
catch(Exception ex)
{
LogTaskFailure(task);
}
finally
{
//close connections, etc
}
}
interface ITaskStep
{
void Execute()
{
}
}
I also wanted to add that the Task Steps are implementing the ITaskStep interface, so the implementation of Execute is not my own (well it is in this instance, but someone could implement the interface). My code just loads up the library and runs any ITasks and their ITaskSteps.