Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in shim delegate doesn't respect try/catch in isolated method #29

Closed
dtkujawski opened this issue Jul 9, 2018 · 3 comments
Closed

Comments

@dtkujawski
Copy link

dtkujawski commented Jul 9, 2018

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()
        {
        }
@tonerdo
Copy link
Owner

tonerdo commented Jul 10, 2018

Hi @dtkujawski, Pose currently doesn't seem to handle try...catch blocks quite well. Will look into it

@tonerdo
Copy link
Owner

tonerdo commented Jul 22, 2018

Hi @dtkujawski #31 added the fix to respect exception handling in methods

@dtkujawski
Copy link
Author

Thank you for the fix! This works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants