title: How to use XCTAssertThrowsSpecific
body: <p>I'm writing Cocoa unit tests using XCTest and recently used XCTAssertThrows for the first time. That's pretty cool, but I want to make it even better with XCTAssertThrowsSpecific and requiring a certain exception.</p>
  
  <p>Here is an example test:</p>
  
  <pre><code>-(void)testShortPassword {
      XCTAssertThrows([user storePassword:@"abc"],@"Expect exception for short pw");
  }
  </code></pre>
  
  <p>And on my user class I have the following code:</p>
  
  <pre><code>-(void)storePassword:(NSString*)password {
  
      NSCAssert(password.length &gt; 6, @"Password must be longer than 6 characters");
  
      // go on to store the password on the keychain
  }
  </code></pre>
  
  <p>Keeping in mind that Cocoa in general shies away from using exceptions (so it might be better to return an error, and show UI in the preceding example, etc.) How do I throw an exception in a manner that can be caught by <code>XCTAssertThrowsSpecific</code>? How do I specify that in <code>XCTAssertThrowsSpecific(expression, specificException, format...)</code>?</p>