I have a section of code that looks like this:
try
{
classVar = functionCall(input, sEnum.First);
classVar = functionCall(input, sEnum.Second);
classVar = functionCall(input, sEnum.Third);
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
}
However my exception dosent show which specific call it came from. The stack trace also only shows details from another class called from inside the function call.
The alternative way to wrap this is:
try
{
classVar = functionCall(input, sEnum.First);
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
}
try
{
classVar = functionCall(input, sEnum.Second);
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
}
try
{
classVar = functionCall(input, sEnum.Thrid);
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
}
Though I think it is much less readable that the previous version.
Is there a pattern for wrapping the function calls or passing off the exceptions in such a way that i can later see where they came from while keeping the code readable?