check that the right error is thrown