{"action":"created","issue":{"url":"https://api.github.com/repos/arrow-kt/arrow/issues/709","repository_url":"https://api.github.com/repos/arrow-kt/arrow","labels_url":"https://api.github.com/repos/arrow-kt/arrow/issues/709/labels{/name}","comments_url":"https://api.github.com/repos/arrow-kt/arrow/issues/709/comments","events_url":"https://api.github.com/repos/arrow-kt/arrow/issues/709/events","html_url":"https://github.com/arrow-kt/arrow/issues/709","id":298944453,"number":709,"title":"Selectively catching exceptions with Try","user":{"login":"vibinr","id":3243556,"avatar_url":"https://avatars0.githubusercontent.com/u/3243556?v=4","gravatar_id":"","url":"https://api.github.com/users/vibinr","html_url":"https://github.com/vibinr","followers_url":"https://api.github.com/users/vibinr/followers","following_url":"https://api.github.com/users/vibinr/following{/other_user}","gists_url":"https://api.github.com/users/vibinr/gists{/gist_id}","starred_url":"https://api.github.com/users/vibinr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vibinr/subscriptions","organizations_url":"https://api.github.com/users/vibinr/orgs","repos_url":"https://api.github.com/users/vibinr/repos","events_url":"https://api.github.com/users/vibinr/events{/privacy}","received_events_url":"https://api.github.com/users/vibinr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-21T12:05:14Z","updated_at":"2018-02-21T12:09:25Z","closed_at":null,"author_association":"NONE","body":"Hi, I tried converting my below imperative try-catch code to use Arrow's Try.\r\n\r\nBefore:\r\n\r\n```kotlin\r\n    return try {\r\n        val contentProvResult = ctx.contentResolver.applyBatch(AUTHORITY, contentProvOps)\r\n        Timber.d(\"Wrote a new contact with result %s\", contentProvResult)\r\n        true\r\n    } catch (e: RemoteException) {\r\n        Timber.e(e)\r\n        false\r\n    } catch (e: OperationApplicationException) {\r\n        Timber.e(e)\r\n        false\r\n    }\r\n```\r\n\r\nAfter:\r\n\r\n```kotlin\r\nreturn Try { ctx.contentResolver.applyBatch(AUTHORITY, contentProvOps) }\r\n    .fold({\r\n        Timber.e(it)\r\n        false\r\n    }, {\r\n        Timber.d(\"Wrote a new contact with result %s\", it)\r\n        true\r\n    })\r\n```\r\n\r\nBut these two don't exactly behave the same way, as the latter one catches Throwable itself.\r\n\r\n(sorry if this question is too rudimentary! I read Try's API and docs, but they didn't help)"},"comment":{"url":"https://api.github.com/repos/arrow-kt/arrow/issues/comments/367306541","html_url":"https://github.com/arrow-kt/arrow/issues/709#issuecomment-367306541","issue_url":"https://api.github.com/repos/arrow-kt/arrow/issues/709","id":367306541,"user":{"login":"pakoito","id":514871,"avatar_url":"https://avatars1.githubusercontent.com/u/514871?v=4","gravatar_id":"","url":"https://api.github.com/users/pakoito","html_url":"https://github.com/pakoito","followers_url":"https://api.github.com/users/pakoito/followers","following_url":"https://api.github.com/users/pakoito/following{/other_user}","gists_url":"https://api.github.com/users/pakoito/gists{/gist_id}","starred_url":"https://api.github.com/users/pakoito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pakoito/subscriptions","organizations_url":"https://api.github.com/users/pakoito/orgs","repos_url":"https://api.github.com/users/pakoito/repos","events_url":"https://api.github.com/users/pakoito/events{/privacy}","received_events_url":"https://api.github.com/users/pakoito/received_events","type":"User","site_admin":false},"created_at":"2018-02-21T12:09:25Z","updated_at":"2018-02-21T12:09:25Z","author_association":"OWNER","body":"Try this:\r\n\r\n```\r\nreturn Try { ctx.contentResolver.applyBatch(AUTHORITY, contentProvOps) }\r\n    .fold({\r\n        when (it) {\r\n          is RemoteException -> ...\r\n          is OperationApplicationException -> ...\r\n          else ->\r\n        }\r\n    }, {\r\n        Timber.d(\"Wrote a new contact with result %s\", it)\r\n        true\r\n    })\r\n```\r\n\r\nYou're not supposed to let exceptions propagate anymore else it defeats the point of using `Try` in the first place, so the else case inside that `when` has to do something about them."}}
{"actor":{"display_login":"pakoito"}}