Exception in shim delegate doesn't respect try/catch in isolated method
dtkujawski opened this issue · comments
David Kujawski commented
Here is some code where MethodA calls MethodB - if there is no exception, MethodA returns "0" otherwise it returns "1". However, if I make a shim for MethodB that calls an exception, Pose execution stops and the exception isn't caught in MethodA.
Is there a way to throw exceptions in shims that are caught in the isolated method?
[Fact]
public void Test()
{
int i = MethodA();
Assert.Equal(0, i);
PoseContext.Isolate(() =>
{
i = MethodA();
}, Shim.Replace(() => MethodB()).With(() => { throw new Exception("test"); }));
Assert.Equal(1, i);
}
public static int MethodA()
{
try
{
MethodB();
}
catch
{
return 1;
}
return 0;
}
public static void MethodB()
{
}
Toni Solarin-Sodara commented
Hi @dtkujawski, Pose currently doesn't seem to handle try...catch
blocks quite well. Will look into it
Toni Solarin-Sodara commented
Hi @dtkujawski #31 added the fix to respect exception handling in methods
David Kujawski commented
Thank you for the fix! This works great.