Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble getting NUnit's Assert.Throws to work properly
    primarykey
    data
    text
    <p>I could have sworn that I've used NUnit's Assert.Throws to determine whether or not a particular exception gets thrown from a method, but <a href="https://stackoverflow.com/questions/2388827/can-anyone-explain-why-dictionary-in-c-doesnt-work-like-mapt-u-in-stl">my memory has failed me before</a>. I read <a href="https://stackoverflow.com/questions/1609536/nunit-assert-throws">this post here on SO</a>, but it didn't answer my question, as I know the correct syntax, and I don't want to do anything with the exception that gets returned (I don't want to look at the Exception's members, though this could be useful down the road).</p> <p>I wrote unit tests to prove my lack of understanding in the use of Dictionary, and couldn't get it handle the KeyNotFoundException that gets thrown. Instead of NUnit catching it and passing the test, I get an unhandled KeyNotFoundException error when I run. I verified that I don't have the VS IDE set up to break on thrown .NET exceptions.</p> <p>I've tried this two ways:</p> <pre><code>Assert.Throws( typeof(KeyNotFoundException), () =&gt; value = prefs["doesn't exist"]); </code></pre> <p>and</p> <pre><code>Assert.Throws&lt;KeyNotFoundException&gt;( () =&gt; value = prefs["doesn't exist"]); </code></pre> <p>but both result in an unhandled exception. What am I missing here?</p> <p><strong>UPDATE</strong> seems like others can't reproduce this. Here's a screenshot:</p> <p><a href="http://i47.tinypic.com/2qs2hhz.jpg" rel="nofollow noreferrer">alt text http://i47.tinypic.com/2qs2hhz.jpg</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload