Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 535549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:43:42+00:00 2026-05-13T09:43:42+00:00

I am using rhino mocks 3.5 and am trying to throw an exception in

  • 0

I am using rhino mocks 3.5 and am trying to throw an exception in my expectation to test some functionality in my catch block.

But for some reason it is not throwing the exception.

_xyz.stub(x => x.function(string)).throw(new exception("test string"));

So, I am stubbing out the call to the function to throw exception but it is not throwing the exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:43:43+00:00Added an answer on May 13, 2026 at 9:43 am

    I’m not sure why it doesn’t work for you. I created a little sample and it works just fine for me. Take a look at this code:

    First I created the code that I want to test.

    public interface IXyz
    {
        void Foo();
    }
    
    public class Xyz : IXyz
    {
        public void Foo()
        {
        }
    }
    
    public class Sut
    {
        public void Bar(IXyz xyz)
        {
            xyz.Foo();
        }
    }
    

    Next I’m going to create a test method. In this case I’m using MbUnit but it should work with any unit testing framework.

        [Test]
        [ExpectedException(typeof(ArgumentException), Message = "test string")]
        public void BarFoo_Exception()
        {
            IXyz xyzStub = MockRepository.GenerateStub<IXyz>();
            xyzStub.Stub(x => x.Foo()).Throw(new ArgumentException("test string"));
            new Sut().Bar(xyzStub);
        }
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code that I'm trying to test using NUnit and Rhino mocks.
I'm trying to work out why some of my test cases (using RhinoMocks 3.6
I'm using Rhino.Mocks 3.6 for the first time. I'm trying to create a stub
I am trying to test the logic from some existing classes. It is not
We are using Rhino Mocks to perform some unit testing and need to mock
I'm trying to mock (using Rhino.Mocks) a DataService which returns an IDataReader. I Can
I am using VS2010 B2 and EF4 B2 and trying to use Rhino Mocks
Is it possible to mock a static method using Rhino.Mocks? If Rhino does not
Getting Error while running rhinomock test method : Test method TestProject1.UnitTest2.TestMethod1 threw exception: Rhino.Mocks.Exceptions.ExpectationViolationException:
I'm playing around with Rhino Mocks and am trying to set some dummy results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.