Title: Introducing try..catch · Issue #3 · python/exceptiongroups · GitHub
Open Graph Title: Introducing try..catch · Issue #3 · python/exceptiongroups
X Title: Introducing try..catch · Issue #3 · python/exceptiongroups
Description: If we find we really need new syntax to flag that people have thought about the consequences of multi-exceptions, we could switch the existing try..except syntax to try..catch. It seems most other languages use the latter keyword anyway....
Open Graph Description: If we find we really need new syntax to flag that people have thought about the consequences of multi-exceptions, we could switch the existing try..except syntax to try..catch. It seems most other ...
X Description: If we find we really need new syntax to flag that people have thought about the consequences of multi-exceptions, we could switch the existing try..except syntax to try..catch. It seems most other ...
Opengraph URL: https://github.com/python/exceptiongroups/issues/3
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Introducing try..catch","articleBody":"*If* we find we really need new syntax to flag that people have thought about the consequences of multi-exceptions, we could switch the existing `try..except` syntax to `try..catch`. It seems most other languages use the latter keyword anyway.\r\n\r\nSyntax\r\n-------\r\n\r\nThe syntax would just replace `except` with `catch`, leaving everything else the same.\r\n\r\nWe have the option however of disallowing `catch:` (i.e. with no exception, the catch-all block) -- forcing people (and automatic translators) to write `catch BaseException:`.\r\n\r\nNote that `catch` would have to be a soft keyword (supported by the new PEG parser, see PEP 617), since there are plenty of other uses of `catch` in existing code that we don't want to break.\r\n\r\nTransition\r\n----------\r\n\r\nThe transition plan would be that `try..exept` will eventually be removed from the language. There would be three stages:\r\n\r\n1. `try..catch` and `try..except` can both be used.\r\n2. `try..except` works but gives a deprecation warning.\r\n3. `try..except` stops working.\r\n\r\nPossibly stage 2 can be split and `try..except` inside `async` functions can be deprecated sooner than in other contexts.\r\n\r\nDuring stages 1 and 2, each `try` statement must use either `catch` or `except` -- you cannot have both `catch` and `except` blocks in the same statement. (But you can have them in the same file.)\r\n\r\nSemantics\r\n-----------\r\n\r\nWhen the raised exception is not a multi-exception the semantics of `try..catch` is the same as for `try..except`.\r\n\r\nWhen the raised exception is a multi-error the semantics change.\r\n\r\nBasically when a multi-error contains different exception types it is possible that more than one `catch` block runs. E.g.\r\n```\r\ntry:\r\n raise MultiError([ValueError(), ZeroDivisionError(), RuntimeError()]) # or whatever\r\ncatch ValueError:\r\n print(\"VE\")\r\ncatch RuntimeError:\r\n print(\"RE\")\r\n```\r\nwould print \"VE\" and \"RE\" and then raise (bubble up) `RuntimeError()` (or `MultiError([RuntimeError()]`).\r\n\r\nIf there's an `else` block it only gets run if no exceptions were raised in the first place.\r\n\r\nIf there's a `finally` block it gets run after all `catch` blocks (if any) have run, before bubbling up the unhandled exceptions (if any).\r\n\r\nThe order in which the exceptions in the multi-error are handled is just the order in which the `MultiError` object regurgitates them.\r\n\r\nMultiple exceptions of the same type\r\n-------------------------------------\r\n\r\nThis is an open issue.\r\n\r\nWhat if the try block raises `MultiError([ValueError(\"A\"), ValueError(\"B\")])`? We could define different semantics.\r\n\r\nNote that there would also be a question about two different exception classes that derive from the same base class, where the `catch` class specifies that base (or ultimately `catch BaseException`). So we cannot rely on `MultiError` to split exceptions based on class before we start matching exceptions to catch blocks.\r\n\r\n**TO BE CONTINUED IN A LATER COMMENT** (I deleted some meta-comments related to this.)","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2020-10-22T18:22:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":43},"url":"https://github.com/3/exceptiongroups/issues/3"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:02f4a73f-4cb6-9318-39a0-677b085560ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B28C:10CAF0:BC6291:FC3C26:69699713 |
| html-safe-nonce | 7fba5b44fcb26dd917e087b9cfbec011bc3fdc50d3c7016a7087ff2d89f7222d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjhDOjEwQ0FGMDpCQzYyOTE6RkMzQzI2OjY5Njk5NzEzIiwidmlzaXRvcl9pZCI6IjQ3MzI4ODU1OTA2NTI1ODk4NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a274baa625073c3d6db6651bb09835bc44ad9b3cb387c8334e079f18c5f2cada |
| hovercard-subject-tag | issue:727619817 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/exceptiongroups/3/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a99e383ee4315029a02055d68c1d0393c5f2b0a82bc6ab2ce71044e0e62595d3/python/exceptiongroups/issues/3 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a99e383ee4315029a02055d68c1d0393c5f2b0a82bc6ab2ce71044e0e62595d3/python/exceptiongroups/issues/3 |
| og:image:alt | If we find we really need new syntax to flag that people have thought about the consequences of multi-exceptions, we could switch the existing try..except syntax to try..catch. It seems most other ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/exceptiongroups git https://github.com/python/exceptiongroups.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 228462148 |
| octolytics-dimension-repository_nwo | python/exceptiongroups |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 228462148 |
| octolytics-dimension-repository_network_root_nwo | python/exceptiongroups |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | af80af7cc9e3de9c336f18b208a600950a3c187c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width