How to prevent swallowing exceptions caused by unset expectations for a mocked object?
        Posted  
        
            by 
                Schultz9999
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Schultz9999
        
        
        
        Published on 2011-03-04T06:59:02Z
        Indexed on 
            2011/03/04
            7:24 UTC
        
        
        Read the original article
        Hit count: 268
        
I am looking for a way to modify catch block depending on if it's executed during the unit test run or not. The purpose is basically to detect/setup mock expectations which are swallowed because catch doesn't rethrow.
I am using MSTest.
One obvious thing is using preprocessor but I don't think it works. Especially if to use DEBUG define. There should be an easy way to detect that, shouldn't it? I must have been looking for something wrong because I couldn't find much info on that.
try {...}
catch(Exception)
{
    Log(...);
#if DEBUG
        throw;
#endif
}
        © Stack Overflow or respective owner