title: Dart - Unit test for exception in constructor
body: <p>I write some simple project in Dart (1.9.3) with unit tests using <code>unittest</code> library. I have a problem with checking if constructor throws an error. Here's the sample code I write for this issue purposes:</p>
  
  <pre class="lang-dart prettyprint-override"><code>class MyAwesomeClass {
      String theKey;
  
      MyAwesomeClass();
  
      MyAwesomeClass.fromMap(Map someMap) {
          if (!someMap.containsKey('the_key')) {
              throw new Exception('Invalid object format');
          }
  
          theKey = someMap['the key'];
      }
  }
  </code></pre>
  
  <p>and here are the unit tests:</p>
  
  <pre class="lang-dart prettyprint-override"><code>test('when the object is in wrong format', () {
      Map objectMap = {};
  
      expect(new MyAwesomeClass.fromMap(objectMap), throws);
  });
  </code></pre>
  
  <p>The problem is the test fails with following message:</p>
  
  <pre><code>Test failed: Caught Exception: Invalid object format
  </code></pre>
  
  <p>What do I do wrong? Is it a bug in <code>unittest</code> or should I test exceptions with <code>try..catch</code> and check if exception has been thrown?<br>
  Thanks for all!</p>