{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/67424130","id":67424130,"diff_hunk":"@@ -255,6 +255,29 @@ class RealmTests: TestCase {\n         }\n         XCTAssertEqual(try! Realm().objects(SwiftStringObject.self).count, 0)\n     }\n+    \n+    func testThrowsWrite() {\n+        enum TestError: ErrorType { case Exception }\n+        \n+        do {\n+            try Realm().write {\n+                throw TestError.Exception\n+            }\n+            XCTFail(\"Expected exception thrown in write block to be rethrown.\")\n+        }\n+        catch TestError.Exception { }","path":"RealmSwift-swift2.2/Tests/RealmTests.swift","position":14,"original_position":14,"commit_id":"caeb2c8a426e760be1360ea9c75e3bf32aaa7e3a","original_commit_id":"a11a18ee5063afcb4f247e1607b62c0b27362e55","user":{"login":"JadenGeller","id":4544152,"avatar_url":"https://avatars.githubusercontent.com/u/4544152?v=3","gravatar_id":"","url":"https://api.github.com/users/JadenGeller","html_url":"https://github.com/JadenGeller","followers_url":"https://api.github.com/users/JadenGeller/followers","following_url":"https://api.github.com/users/JadenGeller/following{/other_user}","gists_url":"https://api.github.com/users/JadenGeller/gists{/gist_id}","starred_url":"https://api.github.com/users/JadenGeller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JadenGeller/subscriptions","organizations_url":"https://api.github.com/users/JadenGeller/orgs","repos_url":"https://api.github.com/users/JadenGeller/repos","events_url":"https://api.github.com/users/JadenGeller/events{/privacy}","received_events_url":"https://api.github.com/users/JadenGeller/received_events","type":"User","site_admin":false},"body":"I realize we have an `assertThrows` function, but it wasn't working for me. Does using `try!` turn a Swift exception into an Objective-C exception? Should I expect this to work on Swift error types, or only `NSError`?","created_at":"2016-06-16T21:07:01Z","updated_at":"2016-06-16T21:07:01Z","html_url":"https://github.com/realm/realm-cocoa/pull/3760#discussion_r67424130","pull_request_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments/67424130"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/3760#discussion_r67424130"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760","id":74146239,"html_url":"https://github.com/realm/realm-cocoa/pull/3760","diff_url":"https://github.com/realm/realm-cocoa/pull/3760.diff","patch_url":"https://github.com/realm/realm-cocoa/pull/3760.patch","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3760","number":3760,"state":"open","locked":false,"title":"Allow throws within write block","user":{"login":"JadenGeller","id":4544152,"avatar_url":"https://avatars.githubusercontent.com/u/4544152?v=3","gravatar_id":"","url":"https://api.github.com/users/JadenGeller","html_url":"https://github.com/JadenGeller","followers_url":"https://api.github.com/users/JadenGeller/followers","following_url":"https://api.github.com/users/JadenGeller/following{/other_user}","gists_url":"https://api.github.com/users/JadenGeller/gists{/gist_id}","starred_url":"https://api.github.com/users/JadenGeller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JadenGeller/subscriptions","organizations_url":"https://api.github.com/users/JadenGeller/orgs","repos_url":"https://api.github.com/users/JadenGeller/repos","events_url":"https://api.github.com/users/JadenGeller/events{/privacy}","received_events_url":"https://api.github.com/users/JadenGeller/received_events","type":"User","site_admin":false},"body":"Currently, the user cannot call throwing functions within a `write` block unless they handle recovery _within_ the block. If the user wishes to propagate the error outside the block, this leads to very convoluted code.\r\n\r\n```swift\r\nvar error: ErrorType?\r\ntry Realm().write {\r\n  do {\r\n    try createInterdimensionalPortal()\r\n  } catch let ohNoes {\r\n    error = ohNoes\r\n  }\r\n}\r\nif let error = error { throw ohNoes }\r\n```\r\n\r\nEven worse, this will not cancel the write transaction, so any changes made before the `throw` will still be committed to the database. This pull request annotates the block parameter of `write` as `throws` so that it can optionally throw an exception, propagating that exception outside of the write block and canceling the transaction. Now, the above code can be properly written:\r\n```swift\r\ntry Reaml().write {\r\n  try createInterdimensionalPortal()\r\n}\r\n```","created_at":"2016-06-16T20:26:27Z","updated_at":"2016-06-16T21:07:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ba90b1ab6ab8bcb2d25c0ed9e80d5b2b59d5b881","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760/commits","review_comments_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760/comments","review_comment_url":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3760/comments","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/caeb2c8a426e760be1360ea9c75e3bf32aaa7e3a","head":{"label":"realm:jg-write-block-throws","ref":"jg-write-block-throws","sha":"caeb2c8a426e760be1360ea9c75e3bf32aaa7e3a","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4044891,"name":"realm-cocoa","full_name":"realm/realm-cocoa","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-cocoa","description":"Realm is a mobile database: a replacement for Core Data & SQLite","fork":false,"url":"https://api.github.com/repos/realm/realm-cocoa","forks_url":"https://api.github.com/repos/realm/realm-cocoa/forks","keys_url":"https://api.github.com/repos/realm/realm-cocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-cocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-cocoa/teams","hooks_url":"https://api.github.com/repos/realm/realm-cocoa/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-cocoa/events","assignees_url":"https://api.github.com/repos/realm/realm-cocoa/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-cocoa/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-cocoa/tags","blobs_url":"https://api.github.com/repos/realm/realm-cocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-cocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-cocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-cocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-cocoa/languages","stargazers_url":"https://api.github.com/repos/realm/realm-cocoa/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-cocoa/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-cocoa/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-cocoa/subscription","commits_url":"https://api.github.com/repos/realm/realm-cocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-cocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-cocoa/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-cocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-cocoa/merges","archive_url":"https://api.github.com/repos/realm/realm-cocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-cocoa/downloads","issues_url":"https://api.github.com/repos/realm/realm-cocoa/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-cocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-cocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-cocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-cocoa/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-cocoa/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-cocoa/deployments","created_at":"2012-04-16T20:06:56Z","updated_at":"2016-06-16T15:09:55Z","pushed_at":"2016-06-16T20:43:57Z","git_url":"git://github.com/realm/realm-cocoa.git","ssh_url":"git@github.com:realm/realm-cocoa.git","clone_url":"https://github.com/realm/realm-cocoa.git","svn_url":"https://github.com/realm/realm-cocoa","homepage":"https://realm.io","size":120974,"stargazers_count":7971,"watchers_count":7971,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":888,"mirror_url":null,"open_issues_count":184,"forks":888,"open_issues":184,"watchers":7971,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"ddd8546267c98f39542fb4e6e8b84b0958f2f26b","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4044891,"name":"realm-cocoa","full_name":"realm/realm-cocoa","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-cocoa","description":"Realm is a mobile database: a replacement for Core Data & SQLite","fork":false,"url":"https://api.github.com/repos/realm/realm-cocoa","forks_url":"https://api.github.com/repos/realm/realm-cocoa/forks","keys_url":"https://api.github.com/repos/realm/realm-cocoa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-cocoa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-cocoa/teams","hooks_url":"https://api.github.com/repos/realm/realm-cocoa/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-cocoa/events","assignees_url":"https://api.github.com/repos/realm/realm-cocoa/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-cocoa/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-cocoa/tags","blobs_url":"https://api.github.com/repos/realm/realm-cocoa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-cocoa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-cocoa/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-cocoa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-cocoa/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-cocoa/languages","stargazers_url":"https://api.github.com/repos/realm/realm-cocoa/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-cocoa/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-cocoa/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-cocoa/subscription","commits_url":"https://api.github.com/repos/realm/realm-cocoa/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-cocoa/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-cocoa/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-cocoa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-cocoa/merges","archive_url":"https://api.github.com/repos/realm/realm-cocoa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-cocoa/downloads","issues_url":"https://api.github.com/repos/realm/realm-cocoa/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-cocoa/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-cocoa/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-cocoa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-cocoa/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-cocoa/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-cocoa/deployments","created_at":"2012-04-16T20:06:56Z","updated_at":"2016-06-16T15:09:55Z","pushed_at":"2016-06-16T20:43:57Z","git_url":"git://github.com/realm/realm-cocoa.git","ssh_url":"git@github.com:realm/realm-cocoa.git","clone_url":"https://github.com/realm/realm-cocoa.git","svn_url":"https://github.com/realm/realm-cocoa","homepage":"https://realm.io","size":120974,"stargazers_count":7971,"watchers_count":7971,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":888,"mirror_url":null,"open_issues_count":184,"forks":888,"open_issues":184,"watchers":7971,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760"},"html":{"href":"https://github.com/realm/realm-cocoa/pull/3760"},"issue":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/3760"},"comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/issues/3760/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-cocoa/pulls/3760/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-cocoa/statuses/caeb2c8a426e760be1360ea9c75e3bf32aaa7e3a"}}}}
{"actor":{"display_login":"JadenGeller"}}